ImageOptim / mozjpeg-rust

Safe Rust wrapper for the MozJPEG library
https://lib.rs/mozjpeg
Other
75 stars 19 forks source link

mozjpeg can unwind through `extern "C" fn` boundary, which is UB #35

Closed SludgePhD closed 1 year ago

SludgePhD commented 1 year ago

This extern "C" fn explicitly unwinds:

https://github.com/ImageOptim/mozjpeg-rust/blob/d0acb82928625e4828ca48b3a6c703c36178a971/src/errormgr.rs#L37-L41

Additionally, it seemingly intentionally makes my program silently exit with an error status, without printing the actual error to stderr. Why? :laughing:

kornelski commented 1 year ago

Yes, I'm waiting for extern "C-unwind" to be stabilized. Until then it's technically UB.

You need to use catch_unwind to handle errors from this crate. Unfortunately, libjpeg can't signal errors without unwinding.

kornelski commented 1 year ago

C-unwind is now stable.