[FFmpeg-devel,1/3] lavf/matroskadec: resync if cluster parsing fails while seeking

Submitted by Rodger Combs on Dec. 9, 2017, 2:24 a.m.

Details

Message ID 20171209022430.85954-1-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs Dec. 9, 2017, 2:24 a.m.
---
 libavformat/matroskadec.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Carl Eugen Hoyos Dec. 10, 2017, 2:03 p.m.
2017-12-09 3:24 GMT+01:00 Rodger Combs <rodger.combs@gmail.com>:

> -            if (matroska_parse_cluster(matroska) < 0)
> -                break;
> +            if ((ret = matroska_parse_cluster(matroska)) < 0) {
> +                if ((ret == AVERROR_EOF) || matroska_resync(matroska, pos) < 0)

If you believe the brackets improve readability, please keep them!

If you agree with me that they make reading the code more
difficult if anything, please remove them.

Carl Eugen
Nicolas George Dec. 10, 2017, 2:08 p.m.
Rodger Combs (2017-12-08):
> ---
>  libavformat/matroskadec.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 496499b553..b51f67af00 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -3528,9 +3528,13 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
>                    SEEK_SET);
>          matroska->current_id = 0;
>          while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) {
> +            int ret;
> +            int64_t pos = avio_tell(matroska->ctx->pb);
>              matroska_clear_queue(matroska);
> -            if (matroska_parse_cluster(matroska) < 0)
> -                break;
> +            if ((ret = matroska_parse_cluster(matroska)) < 0) {

> +                if ((ret == AVERROR_EOF) || matroska_resync(matroska, pos) < 0)

This is discarding the actual error code from matroska_resync().

> +                    break;
> +            }
>          }
>      }
>  

Regards,
Rodger Combs Dec. 11, 2017, 7:01 a.m.
> On Dec 10, 2017, at 08:08, Nicolas George <george@nsup.org> wrote:
> 
> Rodger Combs (2017-12-08):
>> ---
>> libavformat/matroskadec.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>> 
>> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
>> index 496499b553..b51f67af00 100644
>> --- a/libavformat/matroskadec.c
>> +++ b/libavformat/matroskadec.c
>> @@ -3528,9 +3528,13 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
>>                   SEEK_SET);
>>         matroska->current_id = 0;
>>         while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) {
>> +            int ret;
>> +            int64_t pos = avio_tell(matroska->ctx->pb);
>>             matroska_clear_queue(matroska);
>> -            if (matroska_parse_cluster(matroska) < 0)
>> -                break;
>> +            if ((ret = matroska_parse_cluster(matroska)) < 0) {
> 
>> +                if ((ret == AVERROR_EOF) || matroska_resync(matroska, pos) < 0)
> 
> This is discarding the actual error code from matroska_resync().

This is the old read_seek API, so nothing looks at its actual return code (apart to check if it's >=0). In the new API, we'd want this, but I think moving to that is out of scope for this change.

> 
>> +                    break;
>> +            }
>>         }
>>     }
>> 
> 
> Regards,
> 
> -- 
>  Nicolas George
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>

Patch hide | download patch | download mbox

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 496499b553..b51f67af00 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3528,9 +3528,13 @@  static int matroska_read_seek(AVFormatContext *s, int stream_index,
                   SEEK_SET);
         matroska->current_id = 0;
         while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) {
+            int ret;
+            int64_t pos = avio_tell(matroska->ctx->pb);
             matroska_clear_queue(matroska);
-            if (matroska_parse_cluster(matroska) < 0)
-                break;
+            if ((ret = matroska_parse_cluster(matroska)) < 0) {
+                if ((ret == AVERROR_EOF) || matroska_resync(matroska, pos) < 0)
+                    break;
+            }
         }
     }