diff mbox series

[FFmpeg-devel,5/5] avcodec/agm: Test remaining data in decode_raw_intra_rgb()

Message ID 20200209191424.19041-5-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/5] avcodec/midivid: Check vector index
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. 9, 2020, 7:14 p.m. UTC
Fixes: Timeout (270sec -> 25ms)
Fixes: 20485/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5636954207289344

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

Comments

Paul B Mahol Feb. 9, 2020, 7:29 p.m. UTC | #1
lgtm

On 2/9/20, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: Timeout (270sec -> 25ms)
> Fixes:
> 20485/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5636954207289344
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/agm.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/agm.c b/libavcodec/agm.c
> index 80f4697ee5..c5c9a88dd9 100644
> --- a/libavcodec/agm.c
> +++ b/libavcodec/agm.c
> @@ -573,13 +573,16 @@ static int decode_raw_intra_rgb(AVCodecContext *avctx,
> GetByteContext *gbyte, AV
>      uint8_t *dst = frame->data[0] + (avctx->height - 1) *
> frame->linesize[0];
>      uint8_t r = 0, g = 0, b = 0;
>
> +    if (bytestream2_get_bytes_left(gbyte) < 3 * avctx->width *
> avctx->height)
> +        return AVERROR_INVALIDDATA;
> +
>      for (int y = 0; y < avctx->height; y++) {
>          for (int x = 0; x < avctx->width; x++) {
> -            dst[x*3+0] = bytestream2_get_byte(gbyte) + r;
> +            dst[x*3+0] = bytestream2_get_byteu(gbyte) + r;
>              r = dst[x*3+0];
> -            dst[x*3+1] = bytestream2_get_byte(gbyte) + g;
> +            dst[x*3+1] = bytestream2_get_byteu(gbyte) + g;
>              g = dst[x*3+1];
> -            dst[x*3+2] = bytestream2_get_byte(gbyte) + b;
> +            dst[x*3+2] = bytestream2_get_byteu(gbyte) + b;
>              b = dst[x*3+2];
>          }
>          dst -= frame->linesize[0];
> --
> 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. 9, 2020, 8:21 p.m. UTC | #2
On Sun, Feb 09, 2020 at 08:29:06PM +0100, Paul B Mahol wrote:
> lgtm

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/agm.c b/libavcodec/agm.c
index 80f4697ee5..c5c9a88dd9 100644
--- a/libavcodec/agm.c
+++ b/libavcodec/agm.c
@@ -573,13 +573,16 @@  static int decode_raw_intra_rgb(AVCodecContext *avctx, GetByteContext *gbyte, AV
     uint8_t *dst = frame->data[0] + (avctx->height - 1) * frame->linesize[0];
     uint8_t r = 0, g = 0, b = 0;
 
+    if (bytestream2_get_bytes_left(gbyte) < 3 * avctx->width * avctx->height)
+        return AVERROR_INVALIDDATA;
+
     for (int y = 0; y < avctx->height; y++) {
         for (int x = 0; x < avctx->width; x++) {
-            dst[x*3+0] = bytestream2_get_byte(gbyte) + r;
+            dst[x*3+0] = bytestream2_get_byteu(gbyte) + r;
             r = dst[x*3+0];
-            dst[x*3+1] = bytestream2_get_byte(gbyte) + g;
+            dst[x*3+1] = bytestream2_get_byteu(gbyte) + g;
             g = dst[x*3+1];
-            dst[x*3+2] = bytestream2_get_byte(gbyte) + b;
+            dst[x*3+2] = bytestream2_get_byteu(gbyte) + b;
             b = dst[x*3+2];
         }
         dst -= frame->linesize[0];