php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #25581 getimagesize () return incorrect values on bitmap (os2) files
Submitted: 2003-09-17 16:38 UTC Modified: 2003-10-25 10:06 UTC
From: willertan1980 at yahoo dot com Assigned: helly
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.3 OS: *
Private report: No CVE-ID:
 [2003-09-17 16:38 UTC] willertan1980 at yahoo dot com
Description:
------------
getimagesize () return incorrect values on bitmap files

SYSTEM PHP 4.3.1(bundled version gd >1.6) , WinXP IIS 5.1 server, Intel P4 CPU
TESTED image : RGB 24bits OS/2 bitmap (BM) generated by Photoshop 7.0

>>HEX DUMP image data 1st 32bytes - bitmaps header 12 bytes
4d    2c    d0    01    00    00    00    00    00    1a    00    00    00    0c    00   
00    f0    00    a5    00    01    00    18    00    b0    7f    6d    a9    75    62   


i realized that getimagesize () read OS/2 1.x bitmap by using Windows 3.x / OS/2 2.x structure, that is the reason the output was incorrect.

>>DUMP form getimagesize () :
Array ( [0] => 10813680 [1] => 1572865 [2] => 6 [3] => width="10813680" height="1572865" [bits] => 43373 [mime] => image/bmp )

>>DUMP from my own function, bmp_info () (identical to values that given by WinXP properties and photoshop 7)
Array ( [width] => 240 [height] => 165 [planes] => 1 [bits] => 24 [bi_type] => Bitmap [bi_hsz] => 12 [bi_htype] => OS/2 1.x [ncolor] => 16777216 [xdensity] => 96 [ydensity] => 96 [density_mod] => 1 [component] => 3 [compression] => 0 )



>>Header for bmp >= Windows 2.x and OS/2 1.x
typedef struct _WinBMPFileHeader, 14 bytes
{
    WORD   FileType;
    DWORD  FileSize;
    WORD   Reserved1;
    WORD   Reserved2;
    DWORD  BitmapOffset;
} WINBMPFILEHEADER;


Bitmap Windows 3.x should use this format, always 40 bytes

typedef struct tagBITMAPINFOHEADER{
  DWORD  biSize; 
  LONG   biWidth; 
  LONG   biHeight; 
  WORD   biPlanes; 
  WORD   biBitCount; 
  DWORD  biCompression; 
  DWORD  biSizeImage; 
  LONG   biXPelsPerMeter; 
  LONG   biYPelsPerMeter; 
  DWORD  biClrUsed; 
  DWORD  biClrImportant; 
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;

but Bitmap Windows 2.x and OS/2 1.x should read like this, and its always 12 bytes

typedef struct _Win2xBitmapHeader
{
    DWORD Size;
    SHORT Width;
    SHORT Height;
    WORD  Planes;
    WORD  BitsPerPixel;
} WIN2XBITMAPHEADER;



REFERENCE

http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm
http://netghost.narod.ru/gff/graphics/summary/micbmp.htm

Windows BITMAPINFO-
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_0zn6.asp?frame=true
Windows BITMAPINFOHEADER-
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp?frame=true

http://www.fastgraph.com/help/bmp_header_format.html

*please remove this message if outdated or solved


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-18 15:40 UTC] helly@php.net
You realized wrong. We are only reading the 12 bytes that are the same in all formats. Thus the error must by elsewhere. If you find out where feel free to provide a patch. Until then we simply do not support such images.
 [2003-09-22 00:35 UTC] willertan1980 at yahoo dot com

 [2003-10-25 10:06 UTC] helly@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

Will be fixed in PHP 5b2
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 20:02:01 2014 UTC