Skip to content

Commit

Permalink
std/jpeg: halve maximum scan count from 64 to 32
Browse files Browse the repository at this point in the history
cjpeg defaults to using 1 (sequential) or 10 (progressive) scans. 32 is
still easily more than what's seen in practice.

The previous commit (f9c384d 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
  • Loading branch information
nigeltao committed Jul 24, 2024
1 parent f9c384d commit 42b070e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion release/c/wuffs-unsupported-snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion std/jpeg/decode_jpeg.wuffs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 42b070e

Please sign in to comment.