Fix for decoding large Jp2 images on Windows.

On Windows, the tmpnam function returns a temp filename in the current directory, which has a prepended backslash '\\'.
This subsequently fails the open function.

This patch creates a proper temp filename in the temp folder and makes unlike work by opening the file as short-lived.
This commit is contained in:
Ashod Nakashian 2015-02-11 17:49:19 -05:00
parent 085b4ca741
commit 03ea24f298

View File

@ -365,10 +365,14 @@ jas_stream_t *jas_stream_tmpfile()
#ifdef _WIN32
/* Choose a file name. */
tmpnam(obj->pathname);
char lpTempPathBuffer[MAX_PATH];
const DWORD dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer);
/* Open the underlying file. */
if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY,
if (dwRetVal >= MAX_PATH || dwRetVal == 0 ||
sprintf_s(obj->pathname, MAX_PATH, "%s\\tmp.XXXXXXXXXX", lpTempPathBuffer) <= 0 ||
_mktemp_s(obj->pathname, MAX_PATH) ||
(obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY | O_TEMPORARY | _O_SHORT_LIVED,
JAS_STREAM_PERMS)) < 0) {
jas_stream_destroy(stream);
return 0;