Skip to content

Commit

Permalink
pngload: ensure ADLER32/CRC checking is disabled in non-fail mode
Browse files Browse the repository at this point in the history
The condition was inverted for spng, also sync libpng load while we
are here.
  • Loading branch information
kleisauke committed Apr 8, 2024
1 parent 51a3958 commit f851a94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions libvips/foreign/spngload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions libvips/foreign/vipspng.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit f851a94

Please sign in to comment.