[FFmpeg-devel] [PATCH] gxf only read valid audio samples

Reimar Döffinger Reimar.Doeffinger
Wed Sep 24 21:08:25 CEST 2008


Hello,
On Wed, Sep 24, 2008 at 09:58:47AM -0700, Baptiste Coudurier wrote:
> @@ -441,15 +442,29 @@
>          stream_index = get_sindex(s, track_id, track_type);
>          if (stream_index < 0)
>              return stream_index;
> +        st = s->streams[stream_index];
>          field_nr = get_be32(pb);
> -        get_be32(pb); // field information
> +        field_info = get_be32(pb);
>          get_be32(pb); // "timeline" field number
>          get_byte(pb); // flags
>          get_byte(pb); // reserved
> -        // NOTE: there is also data length information in the
> -        // field information, it might be better to take this into account
> -        // as well.
> +        if (st->codec->codec_id == CODEC_ID_PCM_S24LE ||
> +            st->codec->codec_id == CODEC_ID_PCM_S16LE) {
> +            int first = field_info >> 16;
> +            int last  = field_info & 0xffff; // last is exclusive
> +            int bps = av_get_bits_per_sample(st->codec->codec_id)>>3;
> +            if (first > last || last*bps > pkt_len) {
> +                av_log(s, AV_LOG_ERROR, "invalid first and last sample values\n");
> +                goto read;
> +            }
> +            url_fskip(pb, first*bps);
> +            skip = pkt_len - last*bps;
> +            pkt_len = (last-first)*bps;
> +        }
> +    read:

I am not particularly against goto, but is seems pointless to me here.
if (first <= last && last*bps <= pkt_len) {
...
} else
  av_log(...);

Does not seem much worse.
I suggested the condition this way (av_log in the else part) because it seemed
nicer to me but I do not really care.
If you make a version without goto, feel free to apply directly.

Greetings,
Reimar D?ffinger




More information about the ffmpeg-devel mailing list