Skip to content

Commit a25b43a

Browse files
committed
Fix MCU reference in odd decoding order
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.
1 parent 9fb38ad commit a25b43a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,12 @@ impl<R: Read> Decoder<R> {
582582
let mut mcus_left_until_restart = self.restart_interval;
583583
let mut expected_rst_num = 0;
584584
let mut eob_run = 0;
585-
let mut mcu_row_coefficients = Vec::with_capacity(components.len());
585+
let mut mcu_row_coefficients = vec![vec![]; components.len()];
586586

587587
if !is_progressive {
588-
for (_, component) in components.iter().enumerate().filter(|&(i, _)| finished[i]) {
588+
for (i, component) in components.iter().enumerate().filter(|&(i, _)| finished[i]) {
589589
let coefficients_per_mcu_row = component.block_size.width as usize * component.vertical_sampling_factor as usize * 64;
590-
mcu_row_coefficients.push(vec![0i16; coefficients_per_mcu_row]);
590+
mcu_row_coefficients[i] = vec![0i16; coefficients_per_mcu_row];
591591
}
592592
}
593593

0 commit comments

Comments
 (0)