1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-24 13:56:33 +02:00

avformat/mov: Ignore tags with invalid size during probing

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2021-02-06 18:22:58 +01:00
parent 1ad6801a61
commit 0b78016b2d

View File

@ -7113,15 +7113,21 @@ static int mov_probe(const AVProbeData *p)
offset = 0; offset = 0;
for (;;) { for (;;) {
int64_t size; int64_t size;
int minsize = 8;
/* ignore invalid offset */ /* ignore invalid offset */
if ((offset + 8) > (unsigned int)p->buf_size) if ((offset + 8) > (unsigned int)p->buf_size)
break; break;
size = AV_RB32(p->buf + offset); size = AV_RB32(p->buf + offset);
if (size == 1 && offset + 16 > (unsigned int)p->buf_size) { if (size == 1 && offset + 16 > (unsigned int)p->buf_size) {
size = AV_RB64(p->buf+offset + 8); size = AV_RB64(p->buf+offset + 8);
minsize = 16;
} else if (size == 0) { } else if (size == 0) {
size = p->buf_size - offset; size = p->buf_size - offset;
} }
if (size < minsize) {
offset += 4;
continue;
}
tag = AV_RL32(p->buf + offset + 4); tag = AV_RL32(p->buf + offset + 4);
switch(tag) { switch(tag) {
/* check for obvious tags */ /* check for obvious tags */
@ -7131,9 +7137,7 @@ static int mov_probe(const AVProbeData *p)
case MKTAG('p','n','o','t'): /* detect movs with preview pics like ew.mov and april.mov */ case MKTAG('p','n','o','t'): /* detect movs with preview pics like ew.mov and april.mov */
case MKTAG('u','d','t','a'): /* Packet Video PVAuthor adds this and a lot of more junk */ case MKTAG('u','d','t','a'): /* Packet Video PVAuthor adds this and a lot of more junk */
case MKTAG('f','t','y','p'): case MKTAG('f','t','y','p'):
if (size < 8) { if (tag == MKTAG('f','t','y','p') &&
score = FFMAX(score, AVPROBE_SCORE_EXTENSION);
} else if (tag == MKTAG('f','t','y','p') &&
( AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' ') ( AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' ')
|| AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' ') || AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' ')
)) { )) {
@ -7158,7 +7162,7 @@ static int mov_probe(const AVProbeData *p)
score = FFMAX(score, AVPROBE_SCORE_EXTENSION); score = FFMAX(score, AVPROBE_SCORE_EXTENSION);
break; break;
} }
offset = FFMAX(4, size) + offset; offset += size;
} }
if (score > AVPROBE_SCORE_MAX - 50 && moov_offset != -1) { if (score > AVPROBE_SCORE_MAX - 50 && moov_offset != -1) {
/* moov atom in the header - we should make sure that this is not a /* moov atom in the header - we should make sure that this is not a