diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index ac39b3277b..ea586332b2 100644 --- a/libavcodec/pngdec.c +++ b/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; }