[FFmpeg-cvslog] r15922 - trunk/libavcodec/bmp.c

Kostya kostya.shishkov
Tue Nov 25 08:05:08 CET 2008


On Tue, Nov 25, 2008 at 12:15:26AM +0100, Michael Niedermayer wrote:
> On Mon, Nov 24, 2008 at 11:53:13AM +0100, kostya wrote:
> > Author: kostya
> > Date: Mon Nov 24 11:53:13 2008
> > New Revision: 15922
> > 
> > Log:
> > Add known BMP header sizes.
> > 
> > Now 11B*.bmp from samples repository can be decoded.
> > 
> > 
> > Modified:
> >    trunk/libavcodec/bmp.c
> > 
> > Modified: trunk/libavcodec/bmp.c
> > ==============================================================================
> > --- trunk/libavcodec/bmp.c	(original)
> > +++ trunk/libavcodec/bmp.c	Mon Nov 24 11:53:13 2008
> > @@ -85,13 +85,19 @@ static int bmp_decode_frame(AVCodecConte
> >          return -1;
> >      }
> >  
> > -    if (ihsize == 40) {
> > +    switch(ihsize){
> > +    case  40: // windib v3
> > +    case  64: // OS/2 v2
> > +    case 108: // windib v4
> > +    case 124: // windib v5
> >          width = bytestream_get_le32(&buf);
> >          height = bytestream_get_le32(&buf);
> > -    } else if (ihsize == 12) {
> > +        break;
> > +    case  12: // OS/2 v1
> >          width  = bytestream_get_le16(&buf);
> >          height = bytestream_get_le16(&buf);
> > -    } else {
> > +        break;
> > +    default:
> >          av_log(avctx, AV_LOG_ERROR, "unsupported BMP file, patch welcome\n");
> >          return -1;
> >      }
> 
> you can do this will less crap
> 
> width  = bytestream_get_le32(&buf);
> height = bytestream_get_le32(&buf);
> if(width > 65536U){ 
>     buf -= 8;
>     width  = bytestream_get_le16(&buf);
>     height = bytestream_get_le16(&buf);
> }
> 
> being one option
> using the planes or depth values later is an option too
> or you can just try all variant until one passes the validity checks
> hardcasing header sizes really is fragile
 
The question is where such BMP can come from. While your solution is robust
and pretty, it does not allow catching BMPs with unexpected header sizes.
 
> [...]
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB




More information about the ffmpeg-cvslog mailing list