diff mbox series

[FFmpeg-devel,2/2] avcodec/png: more informative error message for invalid sBIT size

Message ID 20240712190317.294917-2-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
If the sBIT chunk size is invalid, we should print a more informative
error message rather than return an error and print nothing.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
 libavcodec/pngdec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Paul B Mahol July 12, 2024, 7:37 p.m. UTC | #1
You are deeply confused.


Checking with != for overread bytes is wrong.
Leo Izen July 16, 2024, 2:24 a.m. UTC | #2
On 7/12/24 3:03 PM, Leo Izen wrote:
> If the sBIT chunk size is invalid, we should print a more informative
> error message rather than return an error and print nothing.
> 
> Signed-off-by: Leo Izen <leo.izen@gmail.com>
> ---
>   libavcodec/pngdec.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 

Will merge soon.

- Leo Izen (Traneptora)
diff mbox series

Patch

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index b0d02c97dd..cb861e5f60 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1086,8 +1086,11 @@  static int decode_sbit_chunk(AVCodecContext *avctx, PNGDecContext *s,
 
     channels = s->color_type & PNG_COLOR_MASK_PALETTE ? 3 : ff_png_get_nb_channels(s->color_type);
 
-    if (bytestream2_get_bytes_left(gb) != channels)
+    if (bytestream2_get_bytes_left(gb) != channels) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid sBIT size: %d, expected: %d\n",
+            bytestream2_get_bytes_left(gb), channels);
         return AVERROR_INVALIDDATA;
+    }
 
     for (int i = 0; i < channels; i++) {
         int b = bytestream2_get_byteu(gb);