[FFmpeg-devel] [PATCH] h264 parser: detect new extradata on frame parsing.

Michael Niedermayer michaelni at gmx.at
Wed Jul 23 18:19:23 CEST 2014


On Wed, Jul 23, 2014 at 04:05:43PM +0200, Hendrik Leppkes wrote:
> Am 23.07.2014 15:49 schrieb "Benoit Fouet" <benoit.fouet at free.fr>:
> >
> > Try to detect new extradata when parsing frames, and decode it.
> > Fixes issue #3787
> > ---
> >  libavcodec/h264_parser.c | 34 ++++++++++++++++++++++++++++++++++
> >  1 file changed, 34 insertions(+)
> >
> > diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
> > index ea0ab98..c8276a7 100644
> > --- a/libavcodec/h264_parser.c
> > +++ b/libavcodec/h264_parser.c
> > @@ -489,6 +489,40 @@ static int h264_parse(AVCodecParserContext *s,
> >          }
> >      }
> >
> > +    /* See if this is extradata */
> > +    if (h->is_avc &&
> > +        buf_size >= 9 &&
> > +        buf[0] == 1 &&
> > +        (buf[4] & 0xFC) == 0xFC &&
> > +        (buf[5] & 0x1F) &&
> > +        buf[8] == 0x67) {
> > +
> > +        /* Skip the SPSs */
> > +        int cnt = buf[5] & 0x1f;
> > +        const uint8_t *p = buf + 6;
> > +        while (cnt--) {
> > +            int nalsize = AV_RB16(p) + 2;
> > +            if (nalsize > buf_size - (p - buf) || p[2] != 0x67)
> > +                goto not_extra;
> > +            p += nalsize;
> > +        }
> > +
> > +        /* Skip the PPSs */
> > +        cnt = *p++;
> > +        if (!cnt)
> > +            goto not_extra;
> > +        while (cnt--) {
> > +            int nalsize = AV_RB16(p) + 2;
> > +            if (nalsize > buf_size - (p - buf) || p[2] != 0x68)
> > +                goto not_extra;
> > +            p += nalsize;
> > +        }
> > +
> > +        /* Decode (new) extradata */
> > +        return ff_h264_decode_extradata(h, buf, buf_size);
> > +    }
> > +
> > +not_extra:
> >      parse_nal_units(s, avctx, buf, buf_size);
> >
> >      if (h->sei_cpb_removal_delay >= 0) {
> > --
> > 2.0.1.442.g7fe6834
> >
> 
> Having AVC style extradata in the middle of a stream seems like an invalid
> file. The stream should only include NALUs, with start code or with size
> prefix, but not random extra data.

From a quick look at the flv spec i dont see why this would be invalid

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have often repented speaking, but never of holding my tongue.
-- Xenocrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140723/0d57c867/attachment.asc>


More information about the ffmpeg-devel mailing list