aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-08-30 13:20:26 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-05-20 02:11:30 +0200
commit4b93166adde3d84b725f3735c516cf319a828e1c (patch)
tree52904f5cf9a20f651d9e1925f21735a4575a1a5d
parent2dc4034c5a9a40738953697c8fe88a54c7c682a7 (diff)
downloadffmpeg-4b93166adde3d84b725f3735c516cf319a828e1c.tar.gz
avformat/matroskadec: Sanitize SeekHead entries
A Seek element in a Matroska SeekHead should contain a SeekID and a SeekPosition element and upon reading, they should be sanitized: Given that IDs are restricted to 32 bit, longer SeekIDs should be treated as invalid. Instead currently the lower 32 bits have been used. For SeekPosition, no checks were performed for the element to be present and if present, whether it was excessively large (i.e. the absolute file position described by it exceeding INT64_MAX). The SeekPosition element had a default value of -1 which means that a check seems to have been intended; but it was not implemented. This commit adds a check for overflow to the calculation of the absolute file position of the referenced level 1 elements. Using -1 (i.e. UINT64_MAX) as default value for SeekPosition implies that a Seek element without SeekPosition will run afoul of this check. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> (cherry picked from commit 7c243eece3427bc5a6d54657d488d5c0c2985a8e)
-rw-r--r--libavformat/matroskadec.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 724d81b654..41557f0964 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1856,8 +1856,12 @@ static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
MatroskaSeekhead *seekheads = seekhead_list->elem;
uint32_t id = seekheads[i].id;
int64_t pos = seekheads[i].pos + matroska->segment_start;
+ MatroskaLevel1Element *elem;
- MatroskaLevel1Element *elem = matroska_find_level1_elem(matroska, id);
+ if (id != seekheads[i].id || pos < matroska->segment_start)
+ continue;
+
+ elem = matroska_find_level1_elem(matroska, id);
if (!elem || elem->parsed)
continue;