summaryrefslogtreecommitdiff
path: root/libavformat/flvdec.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2016-01-19 10:04:32 +0200
committerMartin Storsjö <martin@martin.st>2016-01-19 14:24:35 +0200
commite4eb13ca77624401ea7cef1ed6ad8e2d13fd2063 (patch)
tree9c0926bc1fa25fe3f50b4707b34b6b0482dacb8c /libavformat/flvdec.c
parent09f4822e4eaf61513b9092414450f3ae920ccd9d (diff)
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>
Diffstat (limited to 'libavformat/flvdec.c')
-rw-r--r--libavformat/flvdec.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index cf9769a439..8b0d201f80 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -846,13 +846,15 @@ skip:
const int64_t fsize = avio_size(s->pb);
avio_seek(s->pb, fsize - 4, SEEK_SET);
size = avio_rb32(s->pb);
- // Seek to the start of the last FLV tag at position (fsize - 4 - size)
- // but skip the byte indicating the type.
- avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
- if (size == avio_rb24(s->pb) + 11) {
- uint32_t ts = avio_rb24(s->pb);
- ts |= avio_r8(s->pb) << 24;
- s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
+ if (size > 0 && size < fsize) {
+ // Seek to the start of the last FLV tag at position (fsize - 4 - size)
+ // but skip the byte indicating the type.
+ avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
+ if (size == avio_rb24(s->pb) + 11) {
+ uint32_t ts = avio_rb24(s->pb);
+ ts |= avio_r8(s->pb) << 24;
+ s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
+ }
}
avio_seek(s->pb, pos, SEEK_SET);
flv->searched_for_end = 1;