9 ms·
“Land initial Rust MP4 parser and unit tests”
- saidajigumi 11y agoAudio, video, and image codecs written in Rust seem like a fantastic early opportunity to investigate Rust's utility for closing down related security vulnerabilities. Is anyone aware of work on fuzz testing an interesting Rust-based "attack surface"(1)? I'm very interested to see what kinds of issues are/aren't turned up in Rust vs. the usual C/C++ code for these libraries. [1] By "attack surface", I'm thinking of traditional bits of code with high exposure to untrusted data: codecs, HTTP parsers, etc.
- pcwalton 11y agoI know we've run the Rust URL parser through AFL. IIRC, it found one panic (brackets in URLs) and nothing else. Nothing security-sensitive was found. (Don't take the statement about security too strongly, however; AFL will not detect logic problems that could result in security issues, such as interactions with TLS hostname validation or whatnot.)
- vbezhenar 11y agoI don't think that production-quality codecs will be written in Rust. As far as I aware, codecs are usually very complex piece of software and employ a lot of hand-written assembly and very low-level C. Rust just doesn't offer anything valuable in this area.
- yrro 11y agoWhat about (de)muxers?
- jfb 11y agoContainer formats are much, much, much simpler and demand much less CPU than sample data formats. One could (and I have) write a perfectly useable ISO parser in emacs lisp, of all things. The reason that they tend to be written in C is because a container parser is not super useful outside of the context of handling the sample data; the overwhelming majority of usages of code that understands containers is to be able to pump out pointers to each individual sample. Doing this across process boundaries would be ... unpleasant.
- steveklabnik 11y agoWe'll see. For inline assembly, sure, it doesn't, but you can do some pretty intense stuff with Rust's type system to guarantee certain static properties. For example, earlier today this comment appeared on Reddit, talking about how to use the type system to guarantee that you're not doing out-of-bound array accesses: http://www.reddit.com/r/rust/comments/3aahl1/outside_of_closures_what_are_some_other_uses_for/csavac5 http://www.reddit.com/r/rust/comments/3aahl1/outside_of_clos... It is true that the lower you go, the less we currently offer, but over time I expect library authors will use this and other future features to check even more properties without runtime overhead.
- chillingeffect 11y agoAs codec operations move into dedicated hardware blocks on silicon, their code will be more about pointing registers at blocks of data and less about performing the mathematics on CPU.
- pcwalton 11y agoA more modern language (modules, closures, pattern matching, package management, type inference) and memory safety are nice. If I were writing a new codec, I'd seriously consider writing the lion's share of it in Rust, to save time and to avoid security problems.
- Alupis 11y agoI think the sentiment of the parent was that we should avoid (re)writing things in pet language of the week. Sure, Rust has a great following, but so does GO. Which is the "right" choice for a new codec? I don't think there is a clear answer.
- Rusky 11y agoFor a codec there is probably a clearer answer than for some other applications- codecs are very performance-sensitive (probably don't want a GC) and also very security-sensitive (you're decoding completely untrusted data). Previously they've always been written in C or C++ because of the performance requirements, and Rust keeps the same performance while adding some more safety checks. Go doesn't.
- geofft 11y agoRust does not require a runtime / garbage collector and offers a programming model that interacts very precisely with external threading requirements. It supports being called from the native platform ABI without initialization, and it supports writing libraries to match an existing, native ("C") ABI and function as a drop-in replacement. Go does not do these things. The suggestion to use Rust here is because this is specifically a thing Rust was designed to do, not because it has a huge following. Go is a great language, but it is designed for different things (and has a following of people who want it to do those different things). If those two languages are the two choices for replacing a codec that functions as a library, there is an objectively correct answer.
- coldtea 11y ago>Sure, Rust has a great following, but so does GO. Which is the "right" choice for a new codec? I don't think there is a clear answer. Sure there is. Go would be an absolutely horrible choice for writing a video codec -- and wasn't even designed for that kind of work in the first place.
- dkhenry 11y agorust code can incorporate assembly just like C can and low-level rust should be just as fast as low level C so it sounds like rust will be a great replacement to write production-quality codecs
- pjc50 11y agoA very complex piece of software is exactly the sort of thing you want to avoid writing in C or assembly. The last person I know writing a codec implementation did it by machine-translating the spec into a functional program that output assembler, C, python, Verilog etc as targets. That did require handcrafting "leaf nodes" for things like matrix multiplication, but they were small enough to verify.
- haberman 11y agoYes, I think of Rust as a promising target for parser generators. Thinking about text parsing, if Bison generated Rust, then you'd have a memory-safe parser that should be about as efficient as C. Something like this probably already exists or is being worked on. Ideally existing code generators could target Rust also to get memory safety. There are some SIMD optimizations in parsers though that I don't know how easily you could express in Rust. The quintessential example of this for text parsing is Clang's optimization that uses SSE to skip over C++ comments 16 bytes at a time: https://github.com/llvm-mirror/clang/blob/61f6bf2c8a8e94c4faed77c5a836329edba91f53/lib/Lex/Lexer.cpp#L2299 https://github.com/llvm-mirror/clang/blob/61f6bf2c8a8e94c4fa...
- steveklabnik 11y agoI am far from an expert in this area, but you can do SIMD with Rust: https://github.com/huonw/simd https://github.com/huonw/simd
- haberman 11y agoThis looks like a good start (though experimental). If it supported something like AltaVec's vec_any_eq() intrinsic on its u8x16 type, that would do the trick. vec_any_eq() takes a vector and a value and returns true if any element of the vector equals the value. On x86 with SSE, this could generate a sequence of two instructions: pcmpeqb (do 16 byte-wise compares) followed by pmovmskb (collect the 16 comparison results into a single byte). Then you'd get the same efficiency as what Clang does (Clang searches 8 bytes at a time for a '/' character when skipping over comments).
- nathan_f77 11y agoI use downvotes pretty sparingly on HN, but I'm afraid you're completely wrong. This is the kind of thing that Rust excels at.
- alexnewman 11y agoAmazing the future is now! How does it perform?
- jffry 11y agoSounds like it's still a work in progress: This isn't functional yet, but I'd like to get the code in tree as a base to build upon.
- comex 11y agoIndeed, the amount of parsing code that was actually imported here is tiny: https://bug1175322.bugzilla.mozilla.org/attachment.cgi?id=8623336 https://bug1175322.bugzilla.mozilla.org/attachment.cgi?id=86...
- jewel 11y agoI imagine that using rust for this is going to mainly provide security benefits. Parsing the MP4 file isn't very CPU intensive; it's a straightforward binary format. (Decoding the video stream is what is CPU intensive, and this code doesn't do that.)
- izietto 11y agoIt would be pretty exciting to see an audio or even a video decoder/encoder written in Rust
- steveklabnik 11y agoSome VLC committers have been experimenting with Rust. Mostly parsing, see https://github.com/geal/nom https://github.com/geal/nom and http://spw15.langsec.org/papers/couprie-nom.pdf http://spw15.langsec.org/papers/couprie-nom.pdf
- izietto 11y agoOh yes I remember about it, it was published on HN some time ago (by you I see :-) ): https://news.ycombinator.com/item?id=9602055 https://news.ycombinator.com/item?id=9602055 I have to read the paper, forgot about it
- scosman 11y agoCan anyone explain why mp4 parsing lib in a specific language is #1 on HN? mp4 is just the container format (not the video stream). I'm not trying to belittle, just curious if I'm missing context.
- Osmose 11y agoI believe it's because this is the first piece of Rust code landing in Firefox.
- steveklabnik 11y agoIt's not the first patch, but it's the first patch that's actually landed, yes.
- davmre 11y agoThis is the first intrusion of Rust into the Firefox source tree. The whole point of Rust and Servo development was that they would eventually lead to safer, cleaner code in Mozilla's shipping web browsers. This code itself doesn't seem significant, but it's a milestone in that it marks the beginning of the payoff from that effort.
- bsdetector 11y agoIt also is vindication for making Rust easy to combine with other languages. If you tried to do this with Go and its own custom stdlib, main(), GC, threads, stacks it would be a nightmare (not to mention an extra 1 MiB to the binary).
- ExpiredLink 11y agoSo Firefox is completely re-witten in Rust? Seriously? Yes / No / Maybe / Don't know?
- pcwalton 11y agoNo.
- lmkg 11y agoThe current plan is to write a new browser called Servo in Rust, which is not intended to supplant Firefox. Servo is currently classified as a research project, not product development, with the goal of exploring parallelism and safety in browser engines. Small, isolated utilities written in Rust may end up in Firefox. (I didn't downvote you, btw. I'm guessing someone thought you were being needlessly sensationalist.)
- Brakenshire 11y agoI think the plan is that FirefoxOS and Firefox for Android will transition over to Servo, presumably because of the major benefits of parallelism on mobile. Desktop, as you say, it's just limited modules.
- molsson 11y agoIs it possible to query the mozilla bugtracker to see how many security issues was fixed in the pre-rust MP4 parser before it was replaced?
- cpeterso 11y agoMost security bugs are private. Even after the bug has been fixed, users running older versions of Firefox may still be affected so Mozilla doesn't want to expose too much information about how to exploit the bug. The fix, of course, is open source for everyone to examine.
- irishcoffee 11y agoMozilla doesn't opensource their bug metadata?! Ah its cool, they're rational actors who don't crucify people for private interests.
- bzbarsky 11y agoMozilla security bugs do get opened up eventually. Specifically, once not only Mozilla but also various downstream distributors (linux distributions, etc) have shipped a fix for it. Release cycles there vary, so there is typically a gap of a month to a bit over a year (depending on whether the fix could be backported to the previous ESR) between the fix shipping in Firefox and the bug being fully disclosed. That said, even after a security bug is open some information in it may remain hidden. For example, weaponized exploits attached to bugs are generally kept hidden even after the bug is opened.
- ossreality 11y agoGIVE IT A FUCKING BREAK. Jesus, find something that actually matters in ANY POSSIBLE WAY to whine about. Do you know how god damn pathetic it is to drag that bullshit into every single thread that relates to Rust or Mozilla. It makes you look pathetic and doesn't garner any sympathy or cause anyone to shed tears for poor ole Brendan. Just let it go for Christ's sake.
- lowellmower 11y agoThis is a test comment
- shmerl 11y agoSo in the future Firefox / Servo will implement decoders in Rust too?
- cpeterso 11y agoThe decoders in Firefox now are third-party libraries (like Google's VP9), so I don't think Mozilla will rewrite them in Rust. Perhaps Mozilla will write the official Daala decoder in Rust?
- shmerl 11y agoDaala decoder in Rust would be neat.
- TD-Linux 11y agoOne of the Daala developers here. The official reference Daala codebase is implemented in C89 - this is to ensure the widest possible compatibility with all sorts of weird platforms. In addition, the tooling for assembly and intrinsics are mature. Of course, this is only the reference implementation - once the bitstream is stable, it'd be great to try writing a decoder in Rust. An easier starting point might be audio or image codecs, where speed is not as critical and the formats are well defined. For example, here is a pure Rust image codec library: https://github.com/PistonDevelopers/image https://github.com/PistonDevelopers/image
- shmerl 11y agoBy the way, do you know if Daala will be renamed to NetVC or not? I don't really like these names like NetVC/ HEVC which sound like some infections. May be it can be kept as Daala? After all Opus wasn't named "NetAC".
- TD-Linux 11y agoOpus's contributing codecs were called CELT and SILK. The IETF working group name was just "CODEC". The name "Opus" was chosen at the end. I imagine a similar procedure will happen in the NETVC working group.