diff mbox

[FFmpeg-devel,07/37] avformat/matroskadec: Set offset of first cluster

Message ID 20190516223018.30827-8-andreas.rheinhardt@gmail.com
State Accepted
Commit 43c3cebbd4c09dd4d2f9122b38f23eddfe7cadbe
Headers show

Commit Message

Andreas Rheinhardt May 16, 2019, 10:29 p.m. UTC
By default, the data_offset member of the AVFormatInternal of the
AVFormatContext associated with the MatroskaDemuxContext has not been
initialized explicitly by any Matroska-specific function, so that it was
initialized by default to the offset at the end of matroska_read_header,
i.e. usually to the offset of the length field of the first encountered
cluster. This meant that in case that the Matroska-specific seek-code
fails because there are no index entries for the target track a seek to
data_offset would be performed and ordinary parsing would start from
there which is nonsense: The length field would be treated as EBML ID and
(if the length field is not longer than four bytes (EBML numbers that
long are rejected as invalid EBML IDs)) whatever comes next would be
treated as its EBML size although it simply isn't.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/matroskadec.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

James Almer June 23, 2019, 4:15 a.m. UTC | #1
On 5/16/2019 7:29 PM, Andreas Rheinhardt wrote:
> By default, the data_offset member of the AVFormatInternal of the
> AVFormatContext associated with the MatroskaDemuxContext has not been
> initialized explicitly by any Matroska-specific function, so that it was
> initialized by default to the offset at the end of matroska_read_header,
> i.e. usually to the offset of the length field of the first encountered
> cluster. This meant that in case that the Matroska-specific seek-code
> fails because there are no index entries for the target track a seek to
> data_offset would be performed and ordinary parsing would start from
> there which is nonsense: The length field would be treated as EBML ID and
> (if the length field is not longer than four bytes (EBML numbers that
> long are rejected as invalid EBML IDs)) whatever comes next would be
> treated as its EBML size although it simply isn't.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/matroskadec.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 927462d3ad..1cda5d5b76 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -2669,6 +2669,9 @@ static int matroska_read_header(AVFormatContext *s)
>          pos = avio_tell(matroska->ctx->pb);
>          res = ebml_parse(matroska, matroska_segment, matroska);
>      }
> +    /* Set data_offset as it might be needed later by seek_frame_generic. */
> +    if (matroska->current_id == MATROSKA_ID_CLUSTER)
> +        s->internal->data_offset = avio_tell(matroska->ctx->pb) - 4;
>      matroska_execute_seekhead(matroska);
>  
>      if (!matroska->time_scale)

Applied, thanks.
diff mbox

Patch

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 927462d3ad..1cda5d5b76 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2669,6 +2669,9 @@  static int matroska_read_header(AVFormatContext *s)
         pos = avio_tell(matroska->ctx->pb);
         res = ebml_parse(matroska, matroska_segment, matroska);
     }
+    /* Set data_offset as it might be needed later by seek_frame_generic. */
+    if (matroska->current_id == MATROSKA_ID_CLUSTER)
+        s->internal->data_offset = avio_tell(matroska->ctx->pb) - 4;
     matroska_execute_seekhead(matroska);
 
     if (!matroska->time_scale)