From f851a945d7772599ab2d23c6c37580dd7881bb26 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 8 Apr 2024 18:47:49 +0200 Subject: [PATCH] pngload: ensure ADLER32/CRC checking is disabled in non-fail mode The condition was inverted for spng, also sync libpng load while we are here. --- libvips/foreign/spngload.c | 4 ++-- libvips/foreign/vipspng.c | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libvips/foreign/spngload.c b/libvips/foreign/spngload.c index e6f397aa8c..c23c1f7078 100644 --- a/libvips/foreign/spngload.c +++ b/libvips/foreign/spngload.c @@ -340,10 +340,10 @@ vips_foreign_load_png_header(VipsForeignLoad *load) /* In non-fail mode, ignore CRC errors. */ flags = 0; - if (load->fail_on >= VIPS_FAIL_ON_ERROR) + if (load->fail_on < VIPS_FAIL_ON_ERROR) flags |= SPNG_CTX_IGNORE_ADLER32; png->ctx = spng_ctx_new(flags); - if (load->fail_on >= VIPS_FAIL_ON_ERROR) + if (load->fail_on < VIPS_FAIL_ON_ERROR) /* Ignore and don't calculate checksums. */ spng_set_crc_action(png->ctx, SPNG_CRC_USE, SPNG_CRC_USE); diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index 99211518cd..55261149e7 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -305,20 +305,18 @@ read_new(VipsSource *source, VipsImage *out, PNG_SKIP_sRGB_CHECK_PROFILE, PNG_OPTION_ON); #endif /*PNG_SKIP_sRGB_CHECK_PROFILE*/ - /* Don't verify ADLER32 checksums (this can produce a lot of - * warnings). + /* In non-fail mode, ignore CRC errors. */ + if (read->fail_on < VIPS_FAIL_ON_ERROR) { #ifdef PNG_IGNORE_ADLER32 - png_set_option(read->pPng, PNG_IGNORE_ADLER32, PNG_OPTION_ON); + png_set_option(read->pPng, PNG_IGNORE_ADLER32, PNG_OPTION_ON); #endif /*PNG_IGNORE_ADLER32*/ - /* Disable CRC checking in fuzzing mode. Most fuzzed images will have - * bad CRCs so this check would break fuzzing. - */ -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - png_set_crc_action(read->pPng, - PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE); -#endif /*FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION*/ + /* Ignore and don't calculate checksums. + */ + png_set_crc_action(read->pPng, + PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE); + } /* libpng has a default soft limit of 1m pixels per axis. */