mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-03 09:10:33 +00:00
M2.6: the JBIG2 cap's doc and test say what happens
The decoder has the same 2^28 cap as decode_jbig2, and can refuse a page first, so the doc says either error can come. The page at the cap decodes, which the test now asserts, rather than failing later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
This commit is contained in:
1 parent
738cbadab7
commit
7d53e07f43
1 file changed
+5
-4
@@ -20,7 +20,8 @@ pub const MAX_JBIG2_PIXELS: u64 = 1 << 28;
|
||||
///
|
||||
/// Errors: `data` or `globals` that don't decode, or a page of another size
|
||||
/// ([`FilterError::Corrupt`]); a page past `max` ([`FilterError::LimitExceeded`]) or
|
||||
/// [`MAX_JBIG2_PIXELS`] ([`FilterError::Unsupported`]).
|
||||
/// [`MAX_JBIG2_PIXELS`] ([`FilterError::Unsupported`], or `Corrupt` from the decoder, which has the
|
||||
/// same cap and can refuse the page first).
|
||||
pub fn decode_jbig2(data: &[u8], globals: Option<&[u8]>, columns: u32, rows: u32, max: usize) -> Result<Vec<u8>, FilterError> {
|
||||
if rows == 0 {
|
||||
return Ok(Vec::new());
|
||||
@@ -137,11 +138,11 @@ mod tests {
|
||||
let page = 26 * h as usize;
|
||||
assert!(matches!(decode_jbig2(&data, None, w, h, page - 1), Err(FilterError::LimitExceeded(m)) if m == page - 1), "a byte short");
|
||||
assert_eq!(decode_jbig2(&data, None, w, h, page).unwrap().len(), page, "the page within max");
|
||||
// 16,384 × 16,384 is 2^28 pixels, and fails only later; a row more is past the cap, here or
|
||||
// in the decoder, which can refuse it first.
|
||||
// 16,384 × 16,384 is 2^28 pixels, which decodes; a row more is past the cap, here or in the
|
||||
// decoder, which has the same one and can refuse it first.
|
||||
let large = |rows| decode_jbig2(&page_of(&data, 16_384, rows), None, 16_384, rows, usize::MAX);
|
||||
assert!(matches!(large(16_385), Err(FilterError::Unsupported(_) | FilterError::Corrupt { .. })), "{:?}", large(16_385));
|
||||
assert!(!matches!(large(16_384), Err(FilterError::Unsupported(_))), "{:?}", large(16_384));
|
||||
assert!(large(16_384).is_ok(), "{:?}", large(16_384).map(|page| page.len()));
|
||||
|
||||
// An extension segment (ISO/IEC 14492 7.4.14), which a decoder skips: its 11-byte header
|
||||
// gives the length of the data after it.
|
||||
|
||||
Reference in new issue
Block a user