From 42b070e48793626362085ace630b1b327bbee4eb Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 24 Jul 2024 22:09:25 +1000 Subject: [PATCH] std/jpeg: halve maximum scan count from 64 to 32 cjpeg defaults to using 1 (sequential) or 10 (progressive) scans. 32 is still easily more than what's seen in practice. The previous commit (f9c384d6 std/jpeg: add "expect multiple scans" check) makes Wuffs more closely match libjpeg. Without that commit, though, this commit halves the time taken to decode the oss-fuzz test case (linked below) from 6 to 3 seconds, in an optimized build. For the debug-sanitizer fuzzer build, without this commit, that test case times out after 60 seconds but this commit should halve the time taken. Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=70340 --- release/c/wuffs-unsupported-snapshot.c | 2 +- std/jpeg/decode_jpeg.wuffs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 89c73f19..f40fa2c9 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -47714,7 +47714,7 @@ wuffs_jpeg__decoder__decode_sos( switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; - if (self->private_impl.f_scan_count >= 64u) { + if (self->private_impl.f_scan_count >= 32u) { status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_scan_count); goto exit; } else if ((self->private_impl.f_scan_count > 0u) && ! self->private_impl.f_expect_multiple_scans) { diff --git a/std/jpeg/decode_jpeg.wuffs b/std/jpeg/decode_jpeg.wuffs index f0deae2b..d6fa4ecf 100644 --- a/std/jpeg/decode_jpeg.wuffs +++ b/std/jpeg/decode_jpeg.wuffs @@ -1257,7 +1257,7 @@ pri func decoder.decode_sos?(src: base.io_reader, workbuf: slice base.u8) { var decode_mcu_result : base.u32 var bitstream_length : base.u32 - if this.scan_count >= 64 { + if this.scan_count >= 32 { return "#unsupported scan count" } else if (this.scan_count > 0) and (not this.expect_multiple_scans) { return "#bad scan count"