From 03ea24f298f90934d71fcbabe4d134286ff34d6e Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Wed, 11 Feb 2015 17:49:19 -0500 Subject: [PATCH] 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. --- 3rdparty/libjasper/jas_stream.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/3rdparty/libjasper/jas_stream.c b/3rdparty/libjasper/jas_stream.c index ca1239c7d9..4c5db5871b 100644 --- a/3rdparty/libjasper/jas_stream.c +++ b/3rdparty/libjasper/jas_stream.c @@ -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;