summaryrefslogtreecommitdiff
path: root/libavformat/dhav.c
diff options
context:
space:
mode:
authorIdan Freiberg <speidy@gmail.com>2021-01-13 14:34:54 +0200
committerPaul B Mahol <onemda@gmail.com>2021-01-14 14:20:02 +0100
commita6912e5b88463b7b39cc3ee4f9338f57ef7ff7e6 (patch)
tree9acebbeaf55bd4404f306c6ac6c2ef74f3de762d /libavformat/dhav.c
parentf6477ac9f4daf3de2604d1cc5b27e66952d610b1 (diff)
avformat/dhav: Fix incorrect non-DHAV chunk skipping logic
DAV files may contain a variable length padding in between chunks filled with 0xff bytes. The current skipping logic is incorrect as it may skip over DHAV chunks not appearing sequentially in the file. We now look for the 'DHAV' tag using a byte-by-byte search in order to handle such situations. Also the dhav->last_good_pos field will not be updated while skipping unrecognized data.
Diffstat (limited to 'libavformat/dhav.c')
-rw-r--r--libavformat/dhav.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/libavformat/dhav.c b/libavformat/dhav.c
index 00e0d8476e..6a6c235e65 100644
--- a/libavformat/dhav.c
+++ b/libavformat/dhav.c
@@ -173,18 +173,9 @@ static int read_chunk(AVFormatContext *s)
if (avio_feof(s->pb))
return AVERROR_EOF;
- if (avio_rl32(s->pb) != MKTAG('D','H','A','V') && dhav->last_good_pos < INT64_MAX - 0x8000) {
- dhav->last_good_pos += 0x8000;
- avio_seek(s->pb, dhav->last_good_pos, SEEK_SET);
-
- while (avio_rl32(s->pb) != MKTAG('D','H','A','V')) {
- if (avio_feof(s->pb) || dhav->last_good_pos >= INT64_MAX - 0x8000)
- return AVERROR_EOF;
- dhav->last_good_pos += 0x8000;
- ret = avio_skip(s->pb, 0x8000 - 4);
- if (ret < 0)
- return ret;
- }
+ while (avio_r8(s->pb) != 'D' || avio_r8(s->pb) != 'H' || avio_r8(s->pb) != 'A' || avio_r8(s->pb) != 'V') {
+ if (avio_feof(s->pb))
+ return AVERROR_EOF;
}
start = avio_tell(s->pb) - 4;