[FFmpeg-cvslog] cafdec: Check return value of avio_seek and avoid modifying state if it fails

Joakim Plate git at videolan.org
Sat Feb 11 01:35:49 CET 2012


ffmpeg | branch: master | Joakim Plate <elupus at ecce.se> | Fri Feb 10 18:47:53 2012 +0000| [af701d42c3550c9927652986229a96404346b1e4] | committer: Justin Ruggles

cafdec: Check return value of avio_seek and avoid modifying state if it fails

Signed-off-by: Paul B Mahol <onemda at gmail.com>
Signed-off-by: Justin Ruggles <justin.ruggles at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=af701d42c3550c9927652986229a96404346b1e4
---

 libavformat/cafdec.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index abde78d..5d214de 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -358,7 +358,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
 {
     AVStream *st = s->streams[0];
     CaffContext *caf = s->priv_data;
-    int64_t pos;
+    int64_t pos, packet_cnt, frame_cnt;
 
     timestamp = FFMAX(timestamp, 0);
 
@@ -367,17 +367,22 @@ static int read_seek(AVFormatContext *s, int stream_index,
         pos = caf->bytes_per_packet * timestamp / caf->frames_per_packet;
         if (caf->data_size > 0)
             pos = FFMIN(pos, caf->data_size);
-        caf->packet_cnt = pos / caf->bytes_per_packet;
-        caf->frame_cnt  = caf->frames_per_packet * caf->packet_cnt;
+        packet_cnt = pos / caf->bytes_per_packet;
+        frame_cnt  = caf->frames_per_packet * packet_cnt;
     } else if (st->nb_index_entries) {
-        caf->packet_cnt = av_index_search_timestamp(st, timestamp, flags);
-        caf->frame_cnt  = st->index_entries[caf->packet_cnt].timestamp;
-        pos             = st->index_entries[caf->packet_cnt].pos;
+        packet_cnt = av_index_search_timestamp(st, timestamp, flags);
+        frame_cnt  = st->index_entries[packet_cnt].timestamp;
+        pos        = st->index_entries[packet_cnt].pos;
     } else {
         return -1;
     }
 
-    avio_seek(s->pb, pos + caf->data_start, SEEK_SET);
+    if (avio_seek(s->pb, pos + caf->data_start, SEEK_SET) < 0)
+        return -1;
+
+    caf->packet_cnt = packet_cnt;
+    caf->frame_cnt  = frame_cnt;
+
     return 0;
 }
 



More information about the ffmpeg-cvslog mailing list