changeset 8204:507854688c43 libavcodec

Some BMP files have file size declared in the header equal to headers size without image data, so try to correct that value before conducting checks on declared file size.
author kostya
date Mon, 24 Nov 2008 11:24:02 +0000
parents 3b90f93d97a6
children 10716aef9852
files bmp.c
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/bmp.c	Mon Nov 24 10:58:32 2008 +0000
+++ b/bmp.c	Mon Nov 24 11:24:02 2008 +0000
@@ -73,18 +73,22 @@
     buf += 2; /* reserved2 */
 
     hsize = bytestream_get_le32(&buf); /* header size */
+    ihsize = bytestream_get_le32(&buf);       /* more header size */
+    if(ihsize + 14 > hsize){
+        av_log(avctx, AV_LOG_ERROR, "invalid header size %d\n", hsize);
+        return -1;
+    }
+
+    /* sometimes file size is set to some headers size, set a real size in that case */
+    if(fsize == 14 || fsize == ihsize + 14)
+        fsize = buf_size - 2;
+
     if(fsize <= hsize){
         av_log(avctx, AV_LOG_ERROR, "declared file size is less than header size (%d < %d)\n",
                fsize, hsize);
         return -1;
     }
 
-    ihsize = bytestream_get_le32(&buf);       /* more header size */
-    if(ihsize + 14 > hsize){
-        av_log(avctx, AV_LOG_ERROR, "invalid header size %d\n", hsize);
-        return -1;
-    }
-
     switch(ihsize){
     case  40: // windib v3
     case  64: // OS/2 v2