[PATCH] [matroska] Check return value of avio_seek and avoid modifying state if it fails
--- libavformat/matroskadec.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3a5940b..7564c2d 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2018,25 +2018,20 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, timestamp = FFMAX(timestamp, st->index_entries[0].timestamp); if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { - avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET); + if (avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET) < 0) + return -1; matroska->current_id = 0; while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { matroska_clear_queue(matroska); if (matroska_parse_cluster(matroska) < 0) break; } - } - - matroska_clear_queue(matroska); - if (index < 0) + matroska_clear_queue(matroska); return 0; + } index_min = index; for (i=0; i < matroska->tracks.nb_elem; i++) { - tracks[i].audio.pkt_cnt = 0; - tracks[i].audio.sub_packet_cnt = 0; - tracks[i].audio.buf_timecode = AV_NOPTS_VALUE; - tracks[i].end_timecode = 0; if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE && !tracks[i].stream->discard != AVDISCARD_ALL) { index_sub = av_index_search_timestamp(tracks[i].stream, st->index_entries[index].timestamp, AVSEEK_FLAG_BACKWARD); @@ -2047,7 +2042,16 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, } } - avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET); + if (avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET) < 0) + return -1; + + matroska_clear_queue(matroska); + for (i=0; i < matroska->tracks.nb_elem; i++) { + tracks[i].audio.pkt_cnt = 0; + tracks[i].audio.sub_packet_cnt = 0; + tracks[i].audio.buf_timecode = AV_NOPTS_VALUE; + tracks[i].end_timecode = 0; + } matroska->current_id = 0; matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY); matroska->skip_to_timecode = st->index_entries[index].timestamp; -- 1.7.6
On Wed, Sep 14, 2011 at 08:12:06PM +0200, Joakim Plate wrote:
--- libavformat/matroskadec.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3a5940b..7564c2d 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2018,25 +2018,20 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, timestamp = FFMAX(timestamp, st->index_entries[0].timestamp);
if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { - avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET); + if (avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET) < 0) + return -1; matroska->current_id = 0; while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) {
it seems this diff was word wraped this reminds me of tools/unwrap-diff :) [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Old school: Use the lowest level language in which you can solve the problem conveniently. New school: Use the highest level language in which the latest supercomputer can solve the problem without the user falling asleep waiting.
On Wed, 14 Sep 2011 20:48:01 +0200, Michael Niedermayer wrote:
On Wed, Sep 14, 2011 at 08:12:06PM +0200, Joakim Plate wrote:
[20 quoted lines suppressed]
it seems this diff was word wraped this reminds me of tools/unwrap-diff :)
[...]
Okey.. seems it's time to stop using imap-send (user error in this case).. Way to many issues with it. /Joakim
a little late review as i hoped aurel would have time to review it On Wed, Sep 14, 2011 at 10:21:27PM +0200, Joakim Plate wrote: [...]
@@ -2018,25 +2018,20 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, timestamp = FFMAX(timestamp, st->index_entries[0].timestamp);
if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { - avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET); + if (avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET) < 0) + return -1; matroska->current_id = 0; while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { matroska_clear_queue(matroska); if (matroska_parse_cluster(matroska) < 0) break; } - } - - matroska_clear_queue(matroska); - if (index < 0) + matroska_clear_queue(matroska); return 0; + }
this doesnt look correct, index is updated in the while() and may be
= 0 and this would skip the subtitle code below
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope
On Fri, 30 Sep 2011 03:56:20 +0200, Michael Niedermayer wrote:
this doesnt look correct, index is updated in the while() and may be
= 0 and this would skip the subtitle code below
Yea, looks like it. Updated patch.
On Sat, Oct 22, 2011 at 06:38:11PM +0200, Joakim Plate wrote:
On Fri, 30 Sep 2011 03:56:20 +0200, Michael Niedermayer wrote:
this doesnt look correct, index is updated in the while() and may be
= 0 and this would skip the subtitle code below
Yea, looks like it. Updated patch.
matroskadec.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 3d813edd3b0c0439a5489927c1a181de0bba8579 0004-matroska-Check-return-value-of-avio_seek-and-avoid-m.patch From 28da54d1e583d02515b57f2dbd1b3291440f7eb7 Mon Sep 17 00:00:00 2001 From: Joakim Plate <elupus@ecce.se> Date: Sat, 22 Oct 2011 18:33:45 +0200 Subject: [PATCH 04/18] [matroska] Check return value of avio_seek and avoid modifying state if it fails
LGTM if tested [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Breaking DRM is a little like attempting to break through a door even though the window is wide open and the only thing in the house is a bunch of things you dont want and which you would get tomorrow for free anyway
On Sat, Oct 22, 2011 at 07:17:02PM +0200, Michael Niedermayer wrote:
On Sat, Oct 22, 2011 at 06:38:11PM +0200, Joakim Plate wrote:
On Fri, 30 Sep 2011 03:56:20 +0200, Michael Niedermayer wrote:
this doesnt look correct, index is updated in the while() and may be
= 0 and this would skip the subtitle code below
Yea, looks like it. Updated patch.
matroskadec.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 3d813edd3b0c0439a5489927c1a181de0bba8579 0004-matroska-Check-return-value-of-avio_seek-and-avoid-m.patch From 28da54d1e583d02515b57f2dbd1b3291440f7eb7 Mon Sep 17 00:00:00 2001 From: Joakim Plate <elupus@ecce.se> Date: Sat, 22 Oct 2011 18:33:45 +0200 Subject: [PATCH 04/18] [matroska] Check return value of avio_seek and avoid modifying state if it fails
LGTM if tested
patch doesnt apply anymore [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB While the State exists there can be no freedom; when there is freedom there will be no State. -- Vladimir Lenin
participants (2)
-
Joakim Plate -
Michael Niedermayer