History

avcodec/sanm: Checks related to negative left/top

Fixes: 423673969/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SANM_fuzzer-5466731806261248 Fixes: out of array access

Michael Niedermayer committed 1 year ago

Commit ab73bd91 parent b849ac01 file · +3 −3Browse files

Unified · Split

libavcodec/sanm.c+3−3
@@ -1654,7 +1654,7 @@ static int process_frame_obj(SANMVideoContext *ctx, GetByteContext *gb) · 1653 unmodified lines
16541654 bytestream2_skip(gb, 2);
16551655 parm2 = bytestream2_get_le16u(gb);
16561656
1657− if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600) {
1657+ if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600 || left + w <= 0 || top + h <= 0) {
16581658 av_log(ctx->avctx, AV_LOG_WARNING,
16591659 "ignoring invalid fobj dimensions: c%d %d %d @ %d %d\n",
16601660 codec, w, h, left, top);
@@ -1715,7 +1715,7 @@ static int process_frame_obj(SANMVideoContext *ctx, GetByteContext *gb) · 54 unmodified lines
17151715 }
17161716 }
17171717 } else {
1718− if (((left + w > ctx->width) || (top + h > ctx->height)) && fsc) {
1718+ if (((left + w > ctx->width) || (top + h > ctx->height)) && (fsc || codec == 20)) {
17191719 /* correct unexpected overly large frames: this happens
17201720 * for instance with The Dig's sq1.san video: it has a few
17211721 * (all black) 640x480 frames halfway in, while the rest is
@@ -1775,11 +1775,11 @@ static int process_frame_obj(SANMVideoContext *ctx, GetByteContext *gb) · 53 unmodified lines
17751775 if ((w == ctx->width) && (h == ctx->height)) {
17761776 memcpy(ctx->fbuf, ctx->frm0, ctx->fbuf_size);
17771777 } else {
1778− uint8_t *dst = (uint8_t *)ctx->fbuf + left + top * ctx->pitch;
17791778 const uint8_t *src = (uint8_t *)ctx->frm0;
17801779 const int cw = FFMIN(w, ctx->width - left);
17811780 const int ch = FFMIN(h, ctx->height - top);
17821781 if ((cw > 0) && (ch > 0) && (left >= 0) && (top >= 0)) {
1782+ uint8_t *dst = (uint8_t *)ctx->fbuf + left + top * ctx->pitch;
17831783 for (int i = 0; i < ch; i++) {
17841784 memcpy(dst, src, cw);
17851785 dst += ctx->pitch;

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