[FFmpeg-devel] [PATCH 1/2] avcodec/pngdec: avoid erroring with sBIT on indexed-color images

Leo Izen leo.izen at gmail.com
Fri Jul 12 22:03:16 EEST 2024


Indexed color images use three colors for sBIT, but the function
ff_png_get_nb_channels returns 1 in this case. We should avoid erroring
out on valid files in this scenario.

Signed-off-by: Leo Izen <leo.izen at gmail.com>
Reported-by: Ramiro Polla <ramiro.polla at gmail.com>
---
 libavcodec/pngdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 180806e5e1..b0d02c97dd 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1084,7 +1084,7 @@ static int decode_sbit_chunk(AVCodecContext *avctx, PNGDecContext *s,
         return AVERROR_INVALIDDATA;
     }
 
-    channels = ff_png_get_nb_channels(s->color_type);
+    channels = s->color_type & PNG_COLOR_MASK_PALETTE ? 3 : ff_png_get_nb_channels(s->color_type);
 
     if (bytestream2_get_bytes_left(gb) != channels)
         return AVERROR_INVALIDDATA;
-- 
2.45.2



More information about the ffmpeg-devel mailing list