avcodec/pngdec: use 8-bit sBIT cap for indexed PNGs per spec

The PNG specification[1] says that sBIT entries must be at most the bit
depth specified in IHDR, unless the PNG is indexed-color, in which case
sBIT must be between 1 and 8. We should not reject valid sBITs on PNGs
with indexed color.

[1]: https://www.w3.org/TR/png-3/#11sBIT

Regression since 84b454935f.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
Reported-by: Ramiro Polla <ramiro.polla@gmail.com>
release/7.0
Leo Izen 6 months ago
parent c77a3b8d29
commit 63e90b338c
No known key found for this signature in database
GPG Key ID: 764E48EA48221833
  1. 2
      libavcodec/pngdec.c

@ -1095,7 +1095,7 @@ static int decode_sbit_chunk(AVCodecContext *avctx, PNGDecContext *s,
bits = FFMAX(b, bits);
}
if (bits < 0 || bits > s->bit_depth) {
if (bits <= 0 || bits > (s->color_type & PNG_COLOR_MASK_PALETTE ? 8 : s->bit_depth)) {
av_log(avctx, AV_LOG_ERROR, "Invalid significant bits: %d\n", bits);
return AVERROR_INVALIDDATA;
}

Loading…
Cancel
Save