flvdec: Add sanity checking of the last packet size

For http, this avoids spurious warnings about failed requests (e.g.
HTTP error 416 Requested Range Not Satisfiable), if the last packet
is truncated and the size read is bogus.

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Martin Storsjö 2016-01-19 10:04:32 +02:00
parent 09f4822e4e
commit e4eb13ca77
1 changed files with 9 additions and 7 deletions

View File

@ -846,6 +846,7 @@ skip:
const int64_t fsize = avio_size(s->pb); const int64_t fsize = avio_size(s->pb);
avio_seek(s->pb, fsize - 4, SEEK_SET); avio_seek(s->pb, fsize - 4, SEEK_SET);
size = avio_rb32(s->pb); size = avio_rb32(s->pb);
if (size > 0 && size < fsize) {
// Seek to the start of the last FLV tag at position (fsize - 4 - size) // Seek to the start of the last FLV tag at position (fsize - 4 - size)
// but skip the byte indicating the type. // but skip the byte indicating the type.
avio_seek(s->pb, fsize - 3 - size, SEEK_SET); avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
@ -854,6 +855,7 @@ skip:
ts |= avio_r8(s->pb) << 24; ts |= avio_r8(s->pb) << 24;
s->duration = ts * (int64_t)AV_TIME_BASE / 1000; s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
} }
}
avio_seek(s->pb, pos, SEEK_SET); avio_seek(s->pb, pos, SEEK_SET);
flv->searched_for_end = 1; flv->searched_for_end = 1;
} }