Skip to content

Commit 2e73647

Browse files
committed
avformat/mlvdec: fix size checks
Fixes: heap-buffer-overflow Fixes: 391962476/clusterfuzz-testcase-minimized-ffmpeg_dem_MLV_fuzzer-5746746587676672 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 251d43a) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
1 parent 6acfaa1 commit 2e73647

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

libavformat/mlvdec.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,25 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
437437
if (size < 16)
438438
return AVERROR_INVALIDDATA;
439439
avio_skip(pb, 12); //timestamp, frameNumber
440-
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
440+
size -= 12;
441+
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
442+
if (size < 8)
443+
return AVERROR_INVALIDDATA;
441444
avio_skip(pb, 8); // cropPosX, cropPosY, panPosX, panPosY
445+
size -= 8;
446+
}
442447
space = avio_rl32(pb);
448+
if (size < space + 4LL)
449+
return AVERROR_INVALIDDATA;
443450
avio_skip(pb, space);
451+
size -= space;
444452

445453
if ((mlv->class[st->id] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) {
446454
ret = AVERROR_PATCHWELCOME;
447455
} else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
448456
ret = av_get_packet(pb, pkt, (st->codecpar->width * st->codecpar->height * st->codecpar->bits_per_coded_sample + 7) >> 3);
449457
} else { // AVMEDIA_TYPE_AUDIO
450-
if (space > UINT_MAX - 24 || size < (24 + space))
451-
return AVERROR_INVALIDDATA;
452-
ret = av_get_packet(pb, pkt, size - (24 + space));
458+
ret = av_get_packet(pb, pkt, size - 4);
453459
}
454460

455461
if (ret < 0)

0 commit comments

Comments
 (0)