Expose structured JPEG XL pixel limits

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 23:13:26 +00:00
1 parent 8fcb191515
commit ade25d64eb
3 files changed
+12 -2

No files matched your search

+1 -1
View File
@@ -56,7 +56,7 @@ fn decode_inner(bytes: &[u8], limits: DecodeLimits, output_color: OutputColor) -
}
let pixels = u64::from(width).saturating_mul(u64::from(height));
if pixels > limits.max_pixels {
return Err(Error::LimitExceeded(format!("{width}×{height} image exceeds the {} pixel limit", limits.max_pixels)));
return Err(Error::PixelLimitExceeded { width, height, max_pixels: limits.max_pixels });
}
// `JxlImageBuilder::read` feeds the full input. Continue in bounded chunks so trailing frame
+10
View File
@@ -100,6 +100,16 @@ pub enum Error {
/// The image exceeds a caller supplied size or allocation limit.
#[error("JPEG XL: limit exceeded: {0}")]
LimitExceeded(String),
/// The encoded dimensions exceed the caller's pixel-count limit.
#[error("JPEG XL: image dimensions {width}×{height} exceed the {max_pixels} pixel limit")]
PixelLimitExceeded {
/// Encoded image width.
width: u32,
/// Encoded image height.
height: u32,
/// Maximum accepted pixel count.
max_pixels: u64,
},
/// The image layout or samples are unsupported.
#[error("JPEG XL: invalid image: {0}")]
InvalidImage(String),
+1 -1
View File
@@ -70,7 +70,7 @@ fn decoder_enforces_input_and_pixel_limits() {
let input_limit = DecodeLimits { max_input_bytes: encoded.len() - 1, ..DecodeLimits::default() };
assert!(matches!(decode(&encoded, input_limit), Err(craft_jxl::Error::LimitExceeded(_))));
let pixel_limit = DecodeLimits { max_pixels: 0, ..DecodeLimits::default() };
assert!(matches!(decode(&encoded, pixel_limit), Err(craft_jxl::Error::LimitExceeded(_))));
assert!(matches!(decode(&encoded, pixel_limit), Err(craft_jxl::Error::PixelLimitExceeded { width: 1, height: 1, max_pixels: 0 })));
}
#[test]