Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
4.6.0
-
None
-
Windows XP, none platform specific
-
80e6ea3e871fa9f0e5a21d48ad893d4ec59c5c1c
Description
QImageWriter has a bug where sometimes it will cause an exception because of null pointers. I tracked down the issue to line 855 in qpnghandler.cpp
const uchar *data = image.bits();
int bpl = image.bytesPerLine();
row_pointers = new png_bytep[height];
uint y;
for (y=0; y<height; y++)
png_write_image(png_ptr, row_pointers);
Notice how const uchar* data is set to image.bits and it assumes that it is valid. The problem is bits always calls "detach()" in this function (since QImageWriter operates on a separate reference so the function performs a deep copy of the shared data) which returns 0 when it is out of memory. All that needs to be done to fix this bug is to check of data is NULL before proceeding and reporting an out of memory error when it is NULL.