[FFmpeg-devel] [PATCH v2 2/2] avformat/mov: re-allow zero sample sizes if that is not the default

Chris Ribble chris.ribble at resi.io
Sun Dec 11 22:34:03 EET 2022


On Sun, Dec 11, 2022 at 5:55 AM Marton Balint <cus at passwd.hu> wrote:
>
> Patch 03d81a044ad587ea83567f75dc36bc3d64278199 disallowed zero sample sizes,
> but there are some files in the wild which have zero sized samples (e.g.
> no audio in some part of a live recording).
>
> Fix this by simply ignoring a trun box with zero sized samples. This approach
> fixes the original timeout issue from fuzzed files differently.
>
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
>  libavformat/mov.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 935b2f8d9f..63e0b614df 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -5121,6 +5121,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>      if (flags & MOV_TRUN_DATA_OFFSET)        data_offset        = avio_rb32(pb);
>      if (flags & MOV_TRUN_FIRST_SAMPLE_FLAGS) first_sample_flags = avio_rb32(pb);
>
> +    if (entries && !frag->size && !(flags & MOV_TRUN_SAMPLE_SIZE)) {
> +        av_log(c->fc, AV_LOG_WARNING, "Ignoring trun box with zero sized samples\n");
> +        entries = 0;
> +    }
> +
>      frag_stream_info = get_current_frag_stream_info(&c->frag_index);
>      if (frag_stream_info) {
>          if (frag_stream_info->next_trun_dts != AV_NOPTS_VALUE) {
> @@ -5293,8 +5298,6 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>          distance++;
>          if (av_sat_add64(dts, sample_duration) != dts + (uint64_t)sample_duration)
>              return AVERROR_INVALIDDATA;
> -        if (!sample_size)
> -            return AVERROR_INVALIDDATA;
>          dts += sample_duration;
>          offset += sample_size;
>          sc->data_size += sample_size;
> --
> 2.35.3

Marton,

This looks great and I've confirmed it fixes the issue. I see the
warning on STDERR about ignoring the trun box: "Ignoring trun box with
zero sized samples", which is great.

Thanks for doing this!

Assuming this is applied to master, would it also be reasonable to
apply it to the 5.1 branch?

-Chris


More information about the ffmpeg-devel mailing list