Fixes: Assertion sc->slice_coding_mode == 0 failed at libavcodec/ffv1enc.c:1667 Fixes: 408838118/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-6493138204295168
Unified · Split
| @@ -38,19 +38,13 @@ RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, · 37 unmodified lines | ||
| 38 | 38 | if (bits == 0) |
| 39 | 39 | return 0; |
| 40 | 40 | |
| 41 | − if (ac != AC_GOLOMB_RICE) { | |
| 42 | − if (c->bytestream_end - c->bytestream < w * 35) { | |
| 41 | + if (sc->slice_coding_mode == 1) { | |
| 42 | + av_assert0(ac != AC_GOLOMB_RICE); | |
| 43 | + if (c->bytestream_end - c->bytestream < (w * bits + 7LL)>>3) { | |
| 43 | 44 | av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n"); |
| 44 | 45 | return AVERROR_INVALIDDATA; |
| 45 | 46 | } |
| 46 | − } else { | |
| 47 | − if (put_bytes_left(&sc->pb, 0) < w * 4) { | |
| 48 | − av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n"); | |
| 49 | − return AVERROR_INVALIDDATA; | |
| 50 | − } | |
| 51 | − } | |
| 52 | 47 | |
| 53 | − if (sc->slice_coding_mode == 1) { | |
| 54 | 48 | for (x = 0; x < w; x++) { |
| 55 | 49 | int i; |
| 56 | 50 | int v = sample[0][x]; |
| @@ -62,6 +56,18 @@ RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, · 5 unmodified lines | ||
| 62 | 56 | return 0; |
| 63 | 57 | } |
| 64 | 58 | |
| 59 | + if (ac != AC_GOLOMB_RICE) { | |
| 60 | + if (c->bytestream_end - c->bytestream < w * 35) { | |
| 61 | + av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n"); | |
| 62 | + return AVERROR_INVALIDDATA; | |
| 63 | + } | |
| 64 | + } else { | |
| 65 | + if (put_bytes_left(&sc->pb, 0) < w * 4) { | |
| 66 | + av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n"); | |
| 67 | + return AVERROR_INVALIDDATA; | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 65 | 71 | for (x = 0; x < w; x++) { |
| 66 | 72 | int diff, context; |
| 67 | 73 | |