From e12f10eef0e0f2652b4e3b0fb7c8f7afdb652916 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 25 Aug 2024 23:03:06 +1000 Subject: [PATCH] std/jpeg: tweak ignore too-short marker code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old speed new speed delta wuffs_jpeg_decode_19k_8bpp/clang14 317MB/s ± 0% 325MB/s ± 0% +2.60% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/clang14 322MB/s ± 0% 325MB/s ± 0% +0.94% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/clang14 864MB/s ± 0% 880MB/s ± 0% +1.84% (p=0.008 n=5+5) wuffs_jpeg_decode_77k_24bpp/clang14 720MB/s ± 0% 730MB/s ± 0% +1.39% (p=0.016 n=4+5) wuffs_jpeg_decode_552k_24bpp_420/clang14 783MB/s ± 0% 794MB/s ± 0% +1.44% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/clang14 884MB/s ± 0% 914MB/s ± 0% +3.39% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/clang14 781MB/s ± 0% 796MB/s ± 0% +1.90% (p=0.008 n=5+5) wuffs_jpeg_decode_19k_8bpp/gcc12 359MB/s ± 0% 360MB/s ± 0% +0.12% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/gcc12 311MB/s ± 0% 310MB/s ± 0% -0.30% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/gcc12 909MB/s ± 0% 915MB/s ± 0% +0.66% (p=0.008 n=5+5) wuffs_jpeg_decode_77k_24bpp/gcc12 747MB/s ± 0% 750MB/s ± 0% +0.34% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_420/gcc12 817MB/s ± 0% 819MB/s ± 0% +0.30% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/gcc12 971MB/s ± 0% 972MB/s ± 0% +0.11% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/gcc12 819MB/s ± 0% 821MB/s ± 0% +0.21% (p=0.008 n=5+5) --- release/c/wuffs-unsupported-snapshot.c | 10 +++++----- std/jpeg/decode_jpeg.wuffs | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 320e924c..15cf5a36 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -49070,14 +49070,14 @@ wuffs_jpeg__decoder__do_decode_image_config( } self->private_impl.f_payload_length = t_4; } - if (self->private_impl.f_payload_length >= 2u) { - self->private_impl.f_payload_length -= 2u; - } else if ((v_marker == 254u) || ((224u <= v_marker) && (v_marker < 240u))) { - continue; - } else { + if (self->private_impl.f_payload_length < 2u) { + if ((v_marker == 254u) || ((224u <= v_marker) && (v_marker < 240u))) { + continue; + } status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker); goto exit; } + self->private_impl.f_payload_length -= 2u; } if (v_marker < 192u) { status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_marker); diff --git a/std/jpeg/decode_jpeg.wuffs b/std/jpeg/decode_jpeg.wuffs index 40ee683f..57541954 100644 --- a/std/jpeg/decode_jpeg.wuffs +++ b/std/jpeg/decode_jpeg.wuffs @@ -426,18 +426,18 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base. } else { this.payload_length = args.src.read_u16be_as_u32?() // Payload length includes the 2 bytes for the u16be just read. - if this.payload_length >= 2 { - this.payload_length -= 2 - } else if (marker == 0xFE) or // COM. - ((0xE0 <= marker) and (marker < 0xF0)) { // APPn. - // Strictly speaking, this is invalid according to Section - // B.1.1.4 "Marker segments". However, libjpeg-turbo allows it - // (for COM and APPn markers; see its jdmarker.c file's - // skip_variable function) so we do too. - continue - } else { + if this.payload_length < 2 { + if (marker == 0xFE) or // COM. + ((0xE0 <= marker) and (marker < 0xF0)) { // APPn. + // Strictly speaking, this is invalid according to Section + // B.1.1.4 "Marker segments". However, libjpeg-turbo allows + // it (for COM and APPn markers; see its jdmarker.c file's + // skip_variable function) so we do too. + continue + } return "#bad marker" } + this.payload_length -= 2 } // Switch on the marker.