darby johnston
2018-10-30 16:11:37 UTC
Hi all,
I was implementing memory-mapped loading of OpenEXR images for my viewer and noticed a crash when loading DWA compressed files. Taking a look at the code it seems that DwaCompressor::uncompress() is writing to the const char * data that is passed to it:
int
DwaCompressor::uncompress
   (const char *inPtr,
    int inSize,
    IMATH_NAMESPACE::Box2i range,
    const char *&outPtr)
{Â Â Â ...
        Int64     *dst = (((Int64 *)inPtr) + i);
       const char *src = (char *)(((Int64 *)inPtr) + i);
       Xdr::read<CharPtrIO> (src, *dst);   ...
}
When the passed data is memory-mapped as read-only this causes a memory access violation on Windows. Copying the data to a temporary buffer and then doing the Xdr conversion fixes the issue; the performance difference should be negligible since this is only for some header data, probably less than 100 bytes. If this seems like an OK change I've attached a patch or can also submit a git pull request.
Thanks, Darby
I was implementing memory-mapped loading of OpenEXR images for my viewer and noticed a crash when loading DWA compressed files. Taking a look at the code it seems that DwaCompressor::uncompress() is writing to the const char * data that is passed to it:
int
DwaCompressor::uncompress
   (const char *inPtr,
    int inSize,
    IMATH_NAMESPACE::Box2i range,
    const char *&outPtr)
{Â Â Â ...
        Int64     *dst = (((Int64 *)inPtr) + i);
       const char *src = (char *)(((Int64 *)inPtr) + i);
       Xdr::read<CharPtrIO> (src, *dst);   ...
}
When the passed data is memory-mapped as read-only this causes a memory access violation on Windows. Copying the data to a temporary buffer and then doing the Xdr conversion fixes the issue; the performance difference should be negligible since this is only for some header data, probably less than 100 bytes. If this seems like an OK change I've attached a patch or can also submit a git pull request.
Thanks, Darby