Message ID | 20240719160420.169775-1-leo.izen@gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,1/2] avcodec/pngdec: use 8-bit sBIT cap for indexed PNGs per spec | expand |
On 7/19/24 12:04 PM, Leo Izen wrote: > 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 84b454935fae2633a8a5dd075e22393f3e8f932f. > > Signed-off-by: Leo Izen <leo.izen@gmail.com> > Reported-by: Ramiro Polla <ramiro.polla@gmail.com> > --- Will merge soon. - Leo Izen (Traneptora)
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index cb861e5f60..c5b32c166d 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -1097,7 +1097,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; }
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 84b454935fae2633a8a5dd075e22393f3e8f932f. Signed-off-by: Leo Izen <leo.izen@gmail.com> Reported-by: Ramiro Polla <ramiro.polla@gmail.com> --- libavcodec/pngdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)