[FFmpeg-devel] [PATCH] dtshsd: fix seeking

Paul B Mahol onemda at gmail.com
Wed Oct 10 16:42:21 CEST 2012


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavformat/dtshddec.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavformat/dtshddec.c b/libavformat/dtshddec.c
index cee4d33..55c4ca6 100644
--- a/libavformat/dtshddec.c
+++ b/libavformat/dtshddec.c
@@ -38,7 +38,7 @@
 #define TIMECODE 0x54494D45434F4445
 
 typedef struct DTSHDDemuxContext {
-    uint64_t    left;
+    uint64_t    data_end;
 } DTSHDDemuxContext;
 
 static int dtshd_probe(AVProbeData *p)
@@ -79,7 +79,9 @@ static int dtshd_read_header(AVFormatContext *s)
 
         switch (chunk_type) {
         case STRMDATA:
-            dtshd->left = chunk_size;
+            dtshd->data_end = chunk_size + avio_tell(pb);
+            if (dtshd->data_end <= chunk_size)
+                return AVERROR_INVALIDDATA;
             return 0;
             break;
         case FILEINFO:
@@ -107,11 +109,12 @@ skip:
 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     DTSHDDemuxContext *dtshd = s->priv_data;
-    uint64_t size;
+    int64_t size, left;
     int ret;
 
-    size = FFMIN(dtshd->left, 1024);
-    if (size == 0)
+    left = dtshd->data_end - avio_tell(s->pb);
+    size = FFMIN(left, 1024);
+    if (size <= 0)
         return AVERROR_EOF;
 
     ret = av_get_packet(s->pb, pkt, size);
@@ -119,7 +122,6 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
         return ret;
 
     pkt->stream_index = 0;
-    dtshd->left -= ret;
 
     return ret;
 }
-- 
1.7.11.4



More information about the ffmpeg-devel mailing list