diff mbox series

[FFmpeg-devel,4/5] avcodec/hevc/hevcdec: Do not allow slices to depend on failed slices

Message ID 20240623230137.1749178-4-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/5] avcodec/aac/aacdec_usac: Test ac in usac | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Michael Niedermayer June 23, 2024, 11:01 p.m. UTC
An alternative would be to leave the context unchanged on failure of hls_slice_header()

Fixes: out of array access
Fixes: NULL pointer dereference
Fixes: 69584/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5931086299856896
Fixes: 69724/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5104066422702080

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/hevc/hevcdec.c | 5 +++++
 libavcodec/hevc/hevcdec.h | 1 +
 2 files changed, 6 insertions(+)

Comments

Anton Khirnov June 25, 2024, 9:04 a.m. UTC | #1
Quoting Michael Niedermayer (2024-06-24 01:01:36)
> An alternative would be to leave the context unchanged on failure of hls_slice_header()

There's already slice_initialized.
diff mbox series

Patch

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 4dd84d4953c..0e0a910641f 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -626,6 +626,10 @@  static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext
 
         if (pps->dependent_slice_segments_enabled_flag)
             sh->dependent_slice_segment_flag = get_bits1(gb);
+        if (sh->dependent_slice_segment_flag && sh->slice_failure) {
+            av_log(s->avctx, AV_LOG_ERROR, "dependent slice failed\n");
+            return AVERROR_INVALIDDATA;
+        }
 
         slice_address_length = av_ceil_log2(sps->ctb_width *
                                             sps->ctb_height);
@@ -3157,6 +3161,7 @@  static int decode_slice(HEVCContext *s, const H2645NAL *nal, GetBitContext *gb)
     int ret;
 
     ret = hls_slice_header(&s->sh, s, gb);
+    s->sh.slice_failure = ret;
     if (ret < 0)
         return ret;
 
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index da4d83e6615..91f20ea26ab 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -213,6 +213,7 @@  typedef struct SliceHeader {
 
     uint8_t first_slice_in_pic_flag;
     uint8_t dependent_slice_segment_flag;
+    uint8_t slice_failure;
     uint8_t pic_output_flag;
     uint8_t colour_plane_id;