diff mbox series

[FFmpeg-devel] avcodec/magicyuv: Check that there are enough lines for interlacing to be possible

Message ID 20200222161415.2929-1-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel] avcodec/magicyuv: Check that there are enough lines for interlacing to be possible
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Michael Niedermayer Feb. 22, 2020, 4:14 p.m. UTC
Fixes: out of array access
Fixes: 20763/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MAGICYUV_fuzzer-5759562508664832

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/magicyuv.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Paul B Mahol Feb. 24, 2020, 11:51 a.m. UTC | #1
lgtm

On 2/22/20, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: out of array access
> Fixes:
> 20763/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MAGICYUV_fuzzer-5759562508664832
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/magicyuv.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
> index 21a32785bc..aacd0d4d7d 100644
> --- a/libavcodec/magicyuv.c
> +++ b/libavcodec/magicyuv.c
> @@ -659,6 +659,17 @@ static int magy_decode_frame(AVCodecContext *avctx,
> void *data,
>          return AVERROR_INVALIDDATA;
>      }
>
> +    if (s->interlaced) {
> +        if ((s->slice_height >> s->vshift[1]) < 2) {
> +            av_log(avctx, AV_LOG_ERROR, "impossible slice height\n");
> +            return AVERROR_INVALIDDATA;
> +        }
> +        if ((avctx->coded_height % s->slice_height) &&
> ((avctx->coded_height % s->slice_height) >> s->vshift[1]) < 2) {
> +            av_log(avctx, AV_LOG_ERROR, "impossible height\n");
> +            return AVERROR_INVALIDDATA;
> +        }
> +    }
> +
>      for (i = 0; i < s->planes; i++) {
>          av_fast_malloc(&s->slices[i], &s->slices_size[i], s->nb_slices *
> sizeof(Slice));
>          if (!s->slices[i])
> --
> 2.17.1
>
> _______________________________________________
> 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".
Michael Niedermayer Feb. 25, 2020, 4:45 p.m. UTC | #2
On Mon, Feb 24, 2020 at 12:51:48PM +0100, Paul B Mahol wrote:
> lgtm

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 21a32785bc..aacd0d4d7d 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -659,6 +659,17 @@  static int magy_decode_frame(AVCodecContext *avctx, void *data,
         return AVERROR_INVALIDDATA;
     }
 
+    if (s->interlaced) {
+        if ((s->slice_height >> s->vshift[1]) < 2) {
+            av_log(avctx, AV_LOG_ERROR, "impossible slice height\n");
+            return AVERROR_INVALIDDATA;
+        }
+        if ((avctx->coded_height % s->slice_height) && ((avctx->coded_height % s->slice_height) >> s->vshift[1]) < 2) {
+            av_log(avctx, AV_LOG_ERROR, "impossible height\n");
+            return AVERROR_INVALIDDATA;
+        }
+    }
+
     for (i = 0; i < s->planes; i++) {
         av_fast_malloc(&s->slices[i], &s->slices_size[i], s->nb_slices * sizeof(Slice));
         if (!s->slices[i])