diff mbox series

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

Message ID 20240712190317.294917-1-leo.izen@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avcodec/pngdec: avoid erroring with sBIT on indexed-color images | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Leo Izen July 12, 2024, 7:03 p.m. UTC
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@gmail.com>
Reported-by: Ramiro Polla <ramiro.polla@gmail.com>
---
 libavcodec/pngdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marton Balint July 18, 2024, 8:47 a.m. UTC | #1
On Fri, 12 Jul 2024, Leo Izen wrote:

> 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.

Please mention that this is a 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(-)
>
> 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);
>

LGTM, also please backport this to the affected branches!

Thanks,
Marton


>     if (bytestream2_get_bytes_left(gb) != channels)
>         return AVERROR_INVALIDDATA;
> -- 
> 2.45.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Leo Izen July 18, 2024, 12:59 p.m. UTC | #2
On 7/18/24 4:47 AM, Marton Balint wrote:
> 
> 
> On Fri, 12 Jul 2024, Leo Izen wrote:
> 
>> 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.
> 
> Please mention that this is a regression since 
> 84b454935fae2633a8a5dd075e22393f3e8f932f.
> 
> 
> LGTM, also please backport this to the affected branches!
> 
> Thanks,
> Marton
> 
> 

Sure, I'll put it in the commit message when I commit it, and I'll 
backport it to the branches that also contain that commit.

- Leo Izen (Traneptora)
diff mbox series

Patch

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;