Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/codecs/hdr/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,19 @@ fn decode_old_rle<R: Read>(r: &mut R, fb: Rgbe8Pixel, buf: &mut [Rgbe8Pixel]) ->
// rl_shift takes care of consecutive RL markers
let rl = rl << rl_shift;
rl_shift += 8;
if x_off + rl <= width {
let end_offset = match x_off.checked_add(rl) {
Some(end) => end,
None => {
return Err(DecoderError::WrongScanlineLength(usize::MAX, width).into());
}
};
if end_offset <= width {
// do run
for b in &mut buf[x_off..x_off + rl] {
for b in &mut buf[x_off..end_offset] {
*b = prev_pixel;
}
} else {
return Err(DecoderError::WrongScanlineLength(x_off + rl, width).into());
return Err(DecoderError::WrongScanlineLength(end_offset, width).into());
};
rl // value to increase x_off by
}
Expand Down
Loading