image-rs / jpeg-decoder

JPEG decoder written in Rust
Apache License 2.0
149 stars 87 forks source link

Add limit for maximum output image #203

Closed vstroebel closed 2 years ago

vstroebel commented 2 years ago

Most image decoding libraries allow limiting the maximum size of the decoded images. This PR adds an setting to the decoder for controlling the maximum amount of bytes allowed for the decoded image based on width height num_components.

The default maximum is set to usize::MAX which means "unlimited" for the current platform. But it might be better to add a lower limit by default because JPEGs can be 2^16-1 * 2^16-1 which would mean a maximum of nearly 16 GiB in case of 4 components...

This possibly fixes #133