Skip to content

Commit

Permalink
Deny missing docs (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
fintelia authored Dec 27, 2023
1 parent 0cfba34 commit cc5ec05
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
14 changes: 8 additions & 6 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ pub enum DecodingError {
ChunkHeaderInvalid([u8; 4]),

/// Some bits were invalid
#[error("Invalid info bits: {name} {value}")]
InfoBitsInvalid { name: &'static str, value: u32 },
#[error("Reserved bits set")]
ReservedBitSet,

/// Invalid compression method
#[error("Invalid compression method")]
InvalidCompressionMethod,

/// Alpha chunk doesn't match the frame's size
#[error("Alpha chunk size mismatch")]
Expand All @@ -59,6 +63,7 @@ pub enum DecodingError {
#[error("Invalid lossless version number: {0}")]
VersionNumberInvalid(u8),

/// Invalid color cache bits
#[error("Invalid color cache bits: {0}")]
InvalidColorCacheBits(u8),

Expand Down Expand Up @@ -634,10 +639,7 @@ impl<R: Read + Seek> WebPDecoder<R> {
let frame_info = self.r.read_u8()?;
let reserved = frame_info & 0b11111100;
if reserved != 0 {
return Err(DecodingError::InfoBitsInvalid {
name: "reserved",
value: reserved.into(),
});
return Err(DecodingError::ReservedBitSet);
}
let use_alpha_blending = frame_info & 0b00000010 == 0;
let dispose = frame_info & 0b00000001 != 0;
Expand Down
31 changes: 4 additions & 27 deletions src/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,7 @@ pub(crate) fn read_extended_header<R: Read>(
let reserved_third = read_3_bytes(reader)?;

if reserved_first != 0 || reserved_second != 0 || reserved_third != 0 {
let value: u32 = if reserved_first != 0 {
reserved_first.into()
} else if reserved_second != 0 {
reserved_second.into()
} else {
reserved_third
};
return Err(DecodingError::InfoBitsInvalid {
name: "reserved",
value,
});
return Err(DecodingError::ReservedBitSet);
}

let canvas_width = read_3_bytes(reader)? + 1;
Expand Down Expand Up @@ -285,21 +275,13 @@ pub(crate) fn read_alpha_chunk<R: Read>(
let compression = info_byte & 0b00000011;

if reserved != 0 {
return Err(DecodingError::InfoBitsInvalid {
name: "reserved",
value: reserved.into(),
});
return Err(DecodingError::ReservedBitSet);
}

let preprocessing = match preprocessing {
0 => false,
1 => true,
_ => {
return Err(DecodingError::InfoBitsInvalid {
name: "reserved",
value: preprocessing.into(),
})
}
_ => return Err(DecodingError::ReservedBitSet),
};

let filtering_method = match filtering {
Expand All @@ -313,12 +295,7 @@ pub(crate) fn read_alpha_chunk<R: Read>(
let lossless_compression = match compression {
0 => false,
1 => true,
_ => {
return Err(DecodingError::InfoBitsInvalid {
name: "lossless compression",
value: compression.into(),
})
}
_ => return Err(DecodingError::InvalidCompressionMethod),
};

let mut framedata = Vec::new();
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Decoding and Encoding of WebP Images
#![forbid(unsafe_code)]
#![deny(missing_docs)]

pub use self::decoder::{DecodingError, WebPDecoder};

Expand Down

0 comments on commit cc5ec05

Please sign in to comment.