diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-01-08 04:49:50 +0100 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2014-01-08 10:22:31 +0100 |
commit | f974c54909dc83e3c74933295718bf2539542044 (patch) | |
tree | eb2ae32d0cacec06db28a8570b353cd9d017561b | |
parent | 71b3235cea40623ece8e9f2d91cda0e1257ac3f7 (diff) | |
download | ffmpeg-f974c54909dc83e3c74933295718bf2539542044.tar.gz |
avformat/mxfdec: detect loops during header parsing
The header parser uses forward and backward parsing, making the
bulletproof prevention of loops difficult, thus this simple
detection code.
If someone improves the forward/backward parsing so it cannot loop
then this commit should be reverted
Fixes Ticket3278
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 1c010fd035c1a14dc73827b84f21f593e969a5d6)
-rw-r--r-- | libavformat/mxfdec.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 06aa8ac617..09482b6054 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1856,6 +1856,8 @@ static int mxf_read_header(AVFormatContext *s) MXFContext *mxf = s->priv_data; KLVPacket klv; int64_t essence_offset = 0; + int64_t last_pos = -1; + uint64_t last_pos_index = 1; int ret; mxf->last_forward_tell = INT64_MAX; @@ -1871,7 +1873,12 @@ static int mxf_read_header(AVFormatContext *s) while (!url_feof(s->pb)) { const MXFMetadataReadTableEntry *metadata; - + if (avio_tell(s->pb) == last_pos) { + av_log(mxf->fc, AV_LOG_ERROR, "MXF structure loop detected\n"); + return AVERROR_INVALIDDATA; + } + if ((1ULL<<61) % last_pos_index++ == 0) + last_pos = avio_tell(s->pb); if (klv_read_packet(&klv, s->pb) < 0) { /* EOF - seek to previous partition or stop */ if(mxf_parse_handle_partition_or_eof(mxf) <= 0) |