image-rs / jpeg-decoder

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

Fix MCU reference in odd decoding order #207

Closed HeroicKatora closed 2 years ago

HeroicKatora commented 2 years ago

This addresses a potential panic due to index errors. When a component is finished then it can be put into a queue. This references the MCU row coefficients, some structure filled for each finished component.

However, the list for these MCU row coefficients is allocated lazily. Previously we would fill it with an instance for each finished component but then used the index of the component (in the list of all components) to access it. This could cause wrong indices or a past-the-end index and subsequent panic.