Live data from Hacker News

Wuffs: Wrangling Untrusted File Formats Safely

github.com

61–70 of 73 posts

Re: Wuffs: Wrangling Untrusted File Formats Safely

#61

Could you use this to make sure users uploading files to your website are correct (i.e only jpegs and valid image data)? But in a fast and safe way, or is this overkill?

Yes, you could. But be careful to make sure that there's no more data left after the decoder finishes, because it's possible to append a ZIP file (or acropcalypse) at the end of any other valid image file data, and decoders usually stop at the end of the image and don't parse past its end, so won't complain about extra data.

Re: Wuffs: Wrangling Untrusted File Formats Safely

#63

Could you use this to make sure users uploading files to your website are correct (i.e only jpegs and valid image data)? But in a fast and safe way, or is this overkill?

Not sure that’s possible. I’m pretty sure it is not safe to assume „parses in wuffs“ -> „is safe in any other decoder“. I’m using wuffs to check user upload (see my recent response in another thread) but I still generate out linear RGBA and work with that. I still consider the original JPEG data hostile.

Re: Wuffs: Wrangling Untrusted File Formats Safely

#64

Wuffs is great. I use it in Substrata ( https://substrata.info/ ) for loading PNGs. It is both faster and safer than LibPNG. It's something around 2x faster than LibPNG in my tests (depending on the PNG file), see timings here: https://github.com/google/wuffs/issues/13#issuecomment-17325... So generally Wuffs is great and you should use it to decode your PNGs. There are some downsides: not all of the obscure bit dept…

The "mango" lib [1] claims to be even faster for PNGs. Actively maintained but doesn't have as much buzz, I think the devs haven't advertised it as much on places like this. Also, it has the funniest testimonials. 1: https://github.com/t0rakka/mango

Speed isn't the only thing that matters; is mango as safe as wuffs in the face of untrusted input?

Re: Wuffs: Wrangling Untrusted File Formats Safely

#65

This is one of my favorite attempts at better programming language safety, because it compiles down to C that can then be shipped like normal C, so you don't get the ecosystem friction like with ex. Rust.

C has a lot of problems as a compilation target as well, from surprising UB (e.g. signed integer overflow) to debugging problems (e.g. #line is woefully inadequate compared to the ability to emit DWARF DIEs) to the inconvenience of setting up a toolchain for end users. To its credit, Wuffs is one of the better projects that compiles to C, because it targets a very restricted domain. But, in general, don't write progr…

Of course C sucks, but since everything under the sun uses it, there's unique value in being able to make it safer without putting a whole new compiler in the process for users. Remember that time the cryptography library in Python decided to add rust? We could have avoided all that pain with wuffs.

Re: Wuffs: Wrangling Untrusted File Formats Safely

#66

This is one of my favorite attempts at better programming language safety, because it compiles down to C that can then be shipped like normal C, so you don't get the ecosystem friction like with ex. Rust.

C has a lot of problems as a compilation target as well, from surprising UB (e.g. signed integer overflow) to debugging problems (e.g. #line is woefully inadequate compared to the ability to emit DWARF DIEs) to the inconvenience of setting up a toolchain for end users. To its credit, Wuffs is one of the better projects that compiles to C, because it targets a very restricted domain. But, in general, don't write progr…

For many of us making a compile to c language is many times more feasible than using something like llvm. I'm not saying it's great mind you but it's probably the best thing available without a runtime.

For debugging i believe you can generate your own source maps and use gdb as a backend to talk with your custom debugger.

Re: Wuffs: Wrangling Untrusted File Formats Safely

#67
post #37

Earlier quoted context omitted.

There are PDF readers that do not support the scripting format extensions. Note this does not prevent unscrupulous companies abusing dominant market positions to voluntarily embed machine and serial hash watermarks. To be clear: formats like pdf, ps, webp, svg, and tiff are so badly implemented in some ecosystems... they can't _ever_ be assumed safe input formats. Thus, at some point people need to spin up an actual…

WUFFS is provably safe - that's the whole schtick. If a WUFFS kernel exists, you can assume it is safe. If it's not proven safe, it doesn't compile. The reason everyone doesn't program in WUFFS is that you have to write a proof that your kernel is safe, which takes a very very very long time.

WUFFS is provably safe, or WUFFS programs are provably safe, using WUFFS as an axiom?

Re: Wuffs: Wrangling Untrusted File Formats Safely

#68

Can Wuffs provide stronger safety guarantees than techniques like WasmBoxC? My understanding is that compiling unsafe C to WASM and back would also guarantee safety with respect to buffer overflows, integer arithmetic overflows and null pointer dereferences. It’s nice not annotating code to explicitly prove invariants to the compiler like you would in say Wuffs or Rust, but I suppose that’s what limits performance.

Yes, Wuffs can do better than WasmBoxC because it does more than sandboxing of the code. It also checks things like integer overflows which can lead to exploits that are technically not memory safety issues, but still potentially dangerous.

But the tradeoff is that you need to rewrite your code for Wuffs, while WasmBoxC can sandbox anything that compiles to wasm and prevent it from corrupting the outside, including existing code in C, C++, Zig, unsafe Rust, etc. etc.

Re: Wuffs: Wrangling Untrusted File Formats Safely

#70

Earlier quoted context omitted.

What's the formal verification story for WUFFS?

For WUFFS the language, or for WUFFS the library, or for the WUFFS tooling today? The clever idea is to have you the programmer in effect write a proof that your code has the desired semantic properties as part of the programming activity and so then the WUFFS transpiler is merely checking that the proof is correct. This leverages your understanding of what you were trying to do.

Apparently Wuffs only proves safety. Verifying the code does what it's supposed to do is done with unit tests.
Post reply on HN