diff mbox series

[FFmpeg-devel,3/4] avcodec/cbs_av1: Fixes: check if the value of cbs_av1_write_uvlc() is supported

Message ID 20200618122026.24534-3-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/4] avcodec/mv30: Fix integer overflows in idct2_1d() | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Michael Niedermayer June 18, 2020, 12:20 p.m. UTC
Fixes: assertion failure
Fixes: left shift of 1 by 31 places cannot be represented in type 'int'
Fixes: 23264/clusterfuzz-testcase-minimized-ffmpeg_BSF_AV1_METADATA_fuzzer-6308429248593920

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

Comments

Andreas Rheinhardt June 18, 2020, 1:02 p.m. UTC | #1
Michael Niedermayer:
> Fixes: assertion failure
> Fixes: left shift of 1 by 31 places cannot be represented in type 'int'
> Fixes: 23264/clusterfuzz-testcase-minimized-ffmpeg_BSF_AV1_METADATA_fuzzer-6308429248593920
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/cbs_av1.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
> index 29b316e011..4092c9dd06 100644
> --- a/libavcodec/cbs_av1.c
> +++ b/libavcodec/cbs_av1.c
> @@ -125,6 +125,8 @@ static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
>          put_bits(pbc, 1, 1);
>      } else {
>          zeroes = av_log2(value + 1);
> +        if (zeroes > 30)
> +            return AVERROR(EINVAL);
>          v = value - (1 << zeroes) + 1;
>          put_bits(pbc, zeroes + 1, 1);
>          put_bits(pbc, zeroes, v);
> 
This will reject valid input. Instead one should just use unsigned; I've
just sent a patch for this [1].

- Andreas

[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-June/264725.html

PS: Maybe one should an av_assert1(range_max < UINT32_MAX) to this
function to ensure that value + 1 does not wraparound? (range_max equals
UINT32_MAX - 1 for the only caller of this function (corresponding to
the only occurence of this syntax element in the spec), so this is
currently certainly true.)
diff mbox series

Patch

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 29b316e011..4092c9dd06 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -125,6 +125,8 @@  static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
         put_bits(pbc, 1, 1);
     } else {
         zeroes = av_log2(value + 1);
+        if (zeroes > 30)
+            return AVERROR(EINVAL);
         v = value - (1 << zeroes) + 1;
         put_bits(pbc, zeroes + 1, 1);
         put_bits(pbc, zeroes, v);