Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore reserved bits in chunks #109

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ quick_error! {
display("Invalid Chunk header: {err:x?}")
}

#[allow(deprecated)]
#[deprecated]
/// Some bits were invalid
ReservedBitSet {
Juliapixel marked this conversation as resolved.
Show resolved Hide resolved
display("Reserved bits set")
}

/// The ALPH chunk preprocessing info flag was invalid
InvalidAlphaPreprocessing {
display("Alpha chunk preprocessing flag invalid")
}

/// Invalid compression method
InvalidCompressionMethod {
display("Invalid compression method")
Expand Down Expand Up @@ -713,10 +720,6 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
}
let duration = extended::read_3_bytes(&mut self.r)?;
let frame_info = self.r.read_u8()?;
let reserved = frame_info & 0b11111100;
if reserved != 0 {
return Err(DecodingError::ReservedBitSet);
}
let use_alpha_blending = frame_info & 0b00000010 == 0;
let dispose = frame_info & 0b00000001 != 0;

Expand Down
16 changes: 3 additions & 13 deletions src/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,14 @@ pub(crate) fn read_extended_header<R: Read>(
) -> Result<WebPExtendedInfo, DecodingError> {
let chunk_flags = reader.read_u8()?;

let reserved_first = chunk_flags & 0b11000000;
let icc_profile = chunk_flags & 0b00100000 != 0;
let alpha = chunk_flags & 0b00010000 != 0;
let exif_metadata = chunk_flags & 0b00001000 != 0;
let xmp_metadata = chunk_flags & 0b00000100 != 0;
let animation = chunk_flags & 0b00000010 != 0;
let reserved_second = chunk_flags & 0b00000001;

let reserved_third = read_3_bytes(reader)?;

if reserved_first != 0 || reserved_second != 0 || reserved_third != 0 {
return Err(DecodingError::ReservedBitSet);
}
// reserved bytes are ignored
let _reserved_bytes = read_3_bytes(reader)?;

let canvas_width = read_3_bytes(reader)? + 1;
let canvas_height = read_3_bytes(reader)? + 1;
Expand Down Expand Up @@ -271,19 +266,14 @@ pub(crate) fn read_alpha_chunk<R: BufRead>(
) -> Result<AlphaChunk, DecodingError> {
let info_byte = reader.read_u8()?;

let reserved = info_byte & 0b11000000;
let preprocessing = (info_byte & 0b00110000) >> 4;
let filtering = (info_byte & 0b00001100) >> 2;
let compression = info_byte & 0b00000011;

if reserved != 0 {
return Err(DecodingError::ReservedBitSet);
}

let preprocessing = match preprocessing {
0 => false,
1 => true,
_ => return Err(DecodingError::ReservedBitSet),
_ => return Err(DecodingError::InvalidAlphaPreprocessing),
};

let filtering_method = match filtering {
Expand Down
Loading