History

avcodec/ffv1enc_template: Fix remaining space check

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

Michael Niedermayer committed 1 year ago

Commit 67040771 parent 27c5e4b1 file · +15 −9Browse files

Unified · Split

libavcodec/ffv1enc_template.c+15−9
@@ -38,19 +38,13 @@ RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, · 37 unmodified lines
3838 if (bits == 0)
3939 return 0;
4040
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) {
4344 av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
4445 return AVERROR_INVALIDDATA;
4546 }
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− }
5247
53− if (sc->slice_coding_mode == 1) {
5448 for (x = 0; x < w; x++) {
5549 int i;
5650 int v = sample[0][x];
@@ -62,6 +56,18 @@ RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, · 5 unmodified lines
6256 return 0;
6357 }
6458
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+
6571 for (x = 0; x < w; x++) {
6672 int diff, context;
6773

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t