IMG_Load bug with .bmp

I think there might be a bug with SDL_image’s IMG_Load. When I try to
load a .bmp file, it works on most .bmp files, but some .bmps cause it
to err.

I took a standard jpg, http://lackeyccg.com/images/test.jpg, and I
opened it in Preview (the standard mac image program) and I saved it
as a “Microsoft BMP”. Preview gave me no other saving options for a
bmp, so I assume the save settings it used were standard.
The result was http://lackeyccg.com/images/test.bmp

Every other program (e.g., photoshop, preview, firefox) seems to
display the .bmp fine, but this particular .bmp causes the following
error in my program when I load it with IMG_Load:

LackeyCCG(94233,0xa094bfa0) malloc: *** mmap(size=4294893568) failed
(error code=12)
*** error: can’t allocate region

I am using SDL_image version 1.2.6. And I know the file isn’t too big
because it is only 76KB.

Any ideas?

-Trevor Agnitti
www.lackeyccg.com

Hey Trevor,

I tried opening your image with SDL 1.3, and I get the same error.

I went through with the debugger, and it looks like your .bmp file is
storing the height as NEGATIVE 160 pixels. Since SDL reads the image
height as an unsigned integer, the negative 160 is read as the
positive number 4294967136, and hence the huge memory allocation which
causes the failure.

Since Mac OS X’s preview saved the image, this strikes me as a bug.

  • Holmes FutrellOn Jun 21, 2008, at 3:12 AM, Trevor Agnitti wrote:

I think there might be a bug with SDL_image’s IMG_Load. When I try
to load a .bmp file, it works on most .bmp files, but some .bmps
cause it to err.

I took a standard jpg, http://lackeyccg.com/images/test.jpg, and I
opened it in Preview (the standard mac image program) and I saved it
as a “Microsoft BMP”. Preview gave me no other saving options for a
bmp, so I assume the save settings it used were standard.
The result was http://lackeyccg.com/images/test.bmp

Every other program (e.g., photoshop, preview, firefox) seems to
display the .bmp fine, but this particular .bmp causes the following
error in my program when I load it with IMG_Load:

LackeyCCG(94233,0xa094bfa0) malloc: *** mmap(size=4294893568) failed
(error code=12)
*** error: can’t allocate region

I am using SDL_image version 1.2.6. And I know the file isn’t too
big because it is only 76KB.

Any ideas?

-Trevor Agnitti
www.lackeyccg.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Just in case it may help someone, if I remember correctly, negative
height indicates that the rows are stored in reverse order.

Peter

2008/6/21 Holmes Futrell :> Hey Trevor,

I tried opening your image with SDL 1.3, and I get the same error.
I went through with the debugger, and it looks like your .bmp file is
storing the height as NEGATIVE 160 pixels. Since SDL reads the image height
as an unsigned integer, the negative 160 is read as the positive number
4294967136, and hence the huge memory allocation which causes the failure.
Since Mac OS X’s preview saved the image, this strikes me as a bug.

  • Holmes Futrell

Yeah… That would be an SDL_image bug if we’re interpreting it right. Can SDL_LoadBMP handle it, or does IMG_Load wrap that?

Jonny D----------------------------------------

Date: Sat, 21 Jun 2008 12:07:59 +0100
From: mackay.pete+sdl at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] IMG_Load bug with .bmp

Just in case it may help someone, if I remember correctly, negative
height indicates that the rows are stored in reverse order.

Peter

2008/6/21 Holmes Futrell :

Hey Trevor,
I tried opening your image with SDL 1.3, and I get the same error.
I went through with the debugger, and it looks like your .bmp file is
storing the height as NEGATIVE 160 pixels. Since SDL reads the image height
as an unsigned integer, the negative 160 is read as the positive number
4294967136, and hence the huge memory allocation which causes the failure.
Since Mac OS X’s preview saved the image, this strikes me as a bug.

  • Holmes Futrell

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Correct - reference: http://www.fileformat.info/format/bmp/egff.htm
SDL should read a LONG (in win32 this is a 32bit signed int).

Peter Mackay wrote:> Just in case it may help someone, if I remember correctly, negative

height indicates that the rows are stored in reverse order.

Peter

2008/6/21 Holmes Futrell :

Hey Trevor,
I tried opening your image with SDL 1.3, and I get the same error.
I went through with the debugger, and it looks like your .bmp file is
storing the height as NEGATIVE 160 pixels. Since SDL reads the image height
as an unsigned integer, the negative 160 is read as the positive number
4294967136, and hence the huge memory allocation which causes the failure.
Since Mac OS X’s preview saved the image, this strikes me as a bug.

  • Holmes Futrell

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I tried having SDL_LoadBMP load that bmp (http://lackeyccg.com/images/test.bmp
) instead of IMG_Load, and it gave the same error:
LackeyCCG(3079,0xa094bfa0) malloc: *** mmap(size=4294893568) failed
(error code=12)
*** error: can’t allocate region

So it seems like this is a bug in both SDL and SDL_image. It seems
like how Preview would have saved it would have been a valid format
for a bmp. And even if it was atypical, I would hope SDL could have
handled it more gracefully. I am glad Holmes Futrell was able to
reproduce this bug so I know it isn’t just me being a goof… this
time at least.

-Trevor Agnitti
www.lackeyccg.comOn Jun 21, 2008, at 11:08 AM, sdl-request at lists.libsdl.org wrote:

Yeah… That would be an SDL_image bug if we’re interpreting it
right. Can SDL_LoadBMP handle it, or does IMG_Load wrap that?

Jonny D

I think this is related to the fact that MS bitmaps are stored “upside
down.” Preview probably stores the height as negative so that for apps
that understand negative heights the image is displayed right side up.

A post on “http://www.fourcc.org/fccbihgt.php” quotes a spec sheet:

"RGB pixel formats may be described with a BITMAPINFOHEADER that

has a negative biHeight value to indicate that the vertical
orientation of the image is top-down, but using the sign of biHeight
to indicate orientation is only valid for RGB (uncompressed) formats.
For other compression types, described with a FOURCC code in the
biCompression field, the FOURCC code uniquely identifies the
compression and orientation. It is not valid to describe the
orientation with the sign of biHeight."

Definitely seems like something that IMG_Load should anticipate. I
have always just rotated the texture for my sdl/opengl apps that had
this upside down problem.

JohnOn Sat, Jun 21, 2008 at 10:28 AM, Trevor Agnitti wrote:

I tried having SDL_LoadBMP load that bmp
(http://lackeyccg.com/images/test.bmp) instead of IMG_Load, and it gave the
same error:
LackeyCCG(3079,0xa094bfa0) malloc: *** mmap(size=4294893568) failed (error
code=12)
*** error: can’t allocate region
So it seems like this is a bug in both SDL and SDL_image. It seems like how
Preview would have saved it would have been a valid format for a bmp. And
even if it was atypical, I would hope SDL could have handled it more
gracefully. I am glad Holmes Futrell was able to reproduce this bug so I
know it isn’t just me being a goof… this time at least.
-Trevor Agnitti
www.lackeyccg.com
On Jun 21, 2008, at 11:08 AM, sdl-request at lists.libsdl.org wrote:

Yeah… That would be an SDL_image bug if we’re interpreting it right. Can
SDL_LoadBMP handle it, or does IMG_Load wrap that?

Jonny D


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org