Hi Hervé,
Recently I've came across a system access violation exception coming from the free image library upon trying to load very large tiff files (40k x 40k resolution). The problem was caused by an incorrect destination data pointer. This bug is due to an unsigned integer overflow at the CalculateScanLine function from Utilities.h.
This function multiplies the signed int "scanline" with an unsigned int "pitch". This multiplication results in a unsigned integer offset, which is added to the "bits" pointer. But when the result of the multiplication is bigger than MAX_UINT, the offset overflows.
The code for reading a tiled tiff file starts by getting the pointer to the last scan line, and then decreasing the pointer with numrows*pitch on every iteration of tile rows. Of course when this pointer is incorrect, the loop will eventually decrease the pointer to protected memory.
Original function:
CalculateScanLine(unsigned char *bits, unsigned pitch, int scanline) {
return (bits + (pitch * scanline));
}
A simple cast to size_t fixes the problem, on the x64 platform the offset is calculated correctly on large images.
CalculateScanLine(unsigned char *bits, unsigned pitch, int scanline) {
return (bits + ((size_t)pitch * scanline));
}
The fixed header is included as an attachment to this ticket.
Kind regards
Jeremy
Anonymous
Hi Jeremy,
Thanks for the patch, it is now commited to the CVS.
Hervé
fixed in release 3.17.0