image-processingjpegcodecimage-compressionopenexr

Crash in openexr when trying to open openexr file on 64-bit machine


I have included openexr source code (downloaded from http://www.openexr.com/downloads.html) to decode openexr images in my project.

I have built my project for 64-bit (on mac as well as on windows) and trying to open following file: https://github.com/openexr/openexr-images/blob/master/ScanLines/Blobbies.exr

It crashes inside openexr source while opening this openexr file.

rgbaFile = new Imf::RgbaInputFile("Blobbies.exr");

rgbaFile->setFrameBuffer(pixel - datawindow.min.x - (y * exrDimension.mWidth), 1, mWidth);

rgbaFile->readPixels(datawindow.min.y, datawindow.max.y);

This file has data window (-20,-20) to (1020,1020) and display window (0,0) to (999,999).

I am able to open it properly when trying on 32-bit build of my project.


Solution

  • I have found the cause of the issue. Issue is not in openexr api but in parameters that are being passed to setFrameBuffer(), i.e.

    pixel - datawindow.min.x - (y * exrDimension.mWidth)

    here, y is of int32 type while exrDimension.mWidth is of unsigned int32 type. when these two are multiplied gives a very large value of unsigned int32 type. The overall type of the result of the expression on is different when received inside setFrameBuffer function. It depends on the architecture of the machine. If arch is 32 bit, it is int32 and if it is 64 bit arch, then it is int64.

    On 32 bit arch, overall result is typecast to int32 which gives correct value, while on 64 bit arch, this value is incorrect due to y being negative, can't be represented in unsigned int32.