[FFmpeg-devel] [PATCH] Electronic Arts TGV decoder

Michael Niedermayer michaelni
Thu Jul 10 11:52:46 CEST 2008


On Thu, Jul 10, 2008 at 07:43:54PM +1000, pross at xvid.org wrote:
> On Thu, Jul 10, 2008 at 01:00:32AM +0200, Michael Niedermayer wrote:
> > On Wed, Jul 09, 2008 at 09:18:13PM +1000, pross at xvid.org wrote:
> > > Hi!
> > > 
> > > Second video codec in the EA series.
> > > 
> > > Samples: http://samples.mplayerhq.hu/game-formats/ea-tgv/
> > > Write-up: http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TGV
> > [...]
> > 
> > > +
> > > +/**
> > > + * Unpack buffer
> > > + * @return 0 on success, -1 on critical buffer underflow
> > > + */
> > > +static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst, int width, int stride) {
> > > +    int size1,size2,offset;
> > > +    int size;
> > > +    int i;
> > > +    int o = 0;
> > > +
> > 
> > > +    if (src+2>src_end)
> > > +        return -1;
> > > +    if ((AV_RB16(&src[0]) & 0x0100))
> > > +        src += 5;
> > > +    else
> > > +        src += 2;
> > > +
> > > +    if (src+4>src_end)
> > > +        return -1;
> > > +    size = AV_RB24(&src[0]);
> > > +    src += 3;
> > 
> > the first end check seems unneeded, and reading a byte would be enough for
> > the if()
> 
> Thanks for the feedback, but can you explain this comment further.
> Why is the first check unnecessary?

Because the input buffers for decoders have at least 8 bytes extra allocated
at their end:
/**
 * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
 * This is mainly needed because some optimized bitstream readers read
 * 32 or 64 bit at once and could read over the end.<br>
 * Note: If the first 23 bits of the additional bytes are not 0, then damaged
 * MPEG bitstreams could cause overread and segfault.
 */
#define FF_INPUT_BUFFER_PADDING_SIZE 8


> What do you mean by the second part of the sentence?

if ((AV_RB16(&src[0]) & 0x0100)) == if (src[0] & 0x01))


> 
> Nb: To be further pedantic, the second check could be src+3>src_end
> (and not +4) because it is only fetching 24-bits.

yes

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The greatest way to live with honor in this world is to be what we pretend
to be. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080710/a3cdf0fa/attachment.pgp>



More information about the ffmpeg-devel mailing list