Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
decoder+mcu_prog: Check for invalid component dimensions.
Browse files Browse the repository at this point in the history
Makes #8 (comment) correctly panic.
  • Loading branch information
etemesi254 committed Aug 7, 2022
1 parent 8443dde commit 3a0ea3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ impl Decoder
/// before trying to decode.
pub(crate) fn check_component_dimensions(&self) -> Result<(), DecodeErrors>
{
// find y component
// find y component
let y_comp = self
.components
.iter()
Expand All @@ -646,6 +646,9 @@ impl Decoder
{
return Err(DecodeErrors::Format(format!("Invalid image width and height stride for component {:?}, expected {}, but found {}", comp.component_id, cb_cr_width, comp.width_stride)));
}
if (comp.horizontal_sample != 1 || comp.vertical_sample != 1) && comp.component_id != ComponentID::Y {
return Err(DecodeErrors::Format(format!("Invalid component ID for {} for {:?} component, expected 1", comp.horizontal_sample,comp.component_id)));
}
}

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions src/mcu_prog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ impl Decoder
&mut self, reader: &mut Cursor<Vec<u8>>, stream: &mut BitStream, buffer: &mut [Vec<i16>; 3],
) -> Result<bool, DecodeErrors>
{
self.check_component_dimensions()?;
stream.reset();
self.components.iter_mut().for_each(|x| x.dc_pred = 0);

Expand Down Expand Up @@ -301,6 +302,7 @@ impl Decoder
if i >= mcu_height{
break;
}

let data: &mut [i16; 64] = buffer.get_mut(k)
.unwrap().get_mut(start..start + 64)
.unwrap().try_into().unwrap();
Expand Down

0 comments on commit 3a0ea3a

Please sign in to comment.