From 738cbadab75051ce120932d5cd83dbe8e8878c6e Mon Sep 17 00:00:00 2001 From: Grzegorz Martens Date: Sat, 31 Oct 2026 08:33:12 +0100 Subject: [PATCH] M2.6: a page past the JBIG2 cap may be refused by the decoder first The test said such a page is refused here, as Unsupported. #5491 makes hayro-jbig2 refuse it when the stream is opened, as Corrupt, so whichever of the two PRs landed second would fail this test. A page past the cap is refused either way, and that's what the test now says. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY --- crates/filters/src/jbig2/decode.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/filters/src/jbig2/decode.rs b/crates/filters/src/jbig2/decode.rs index ae72f9bc83..2ec9f97dd5 100644 --- a/crates/filters/src/jbig2/decode.rs +++ b/crates/filters/src/jbig2/decode.rs @@ -137,9 +137,10 @@ 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. + // 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. 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(_))), "{:?}", large(16_385)); + assert!(matches!(large(16_385), Err(FilterError::Unsupported(_) | FilterError::Corrupt { .. })), "{:?}", large(16_385)); assert!(!matches!(large(16_384), Err(FilterError::Unsupported(_))), "{:?}", large(16_384)); // An extension segment (ISO/IEC 14492 7.4.14), which a decoder skips: its 11-byte header