Page 1 of 1

JP2: JasPer uses tmpnam(), which is broken on Windows

Posted: 2012-08-21T10:25:04-07:00
by sacha
This is not an IM bug, it's a JasPer bug, but nonetheless read on. FWIW I observe this with IM 6.7.7.

I've been debugging a puzzling permissions-related issue relating to decoding JPEG2000 images, and it seems to be this line in JasPer's jas_stream.c that's the culprit:

/* Choose a file name. */
tmpnam(obj->pathname);

Apaprently, on Windows, tmpnam() always returns a temporary filename in the root directory of the current drive (!), which therefore fails for various users who can't write to the root. (I saw these files being created in my process trace, and after some googling came across this: http://docs.python.org/library/os.html#os.tmpnam)

Various distributions patch around this tmpnam() for other reasons:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=506739

https://bugzilla.redhat.com/show_bug.cgi?id=461477

I've reported this to the JasPer maintainer, but perhaps IM ought to patch it too in the meantime? (Ideally, it would use MAGICK_TMPDIR.)

Re: JP2: JasPer uses tmpnam(), which is broken on Windows

Posted: 2012-08-22T08:00:00-07:00
by sacha
Some further info:

1) The semantics of tmpnam() on Windows are odd, in that if it returns a filename beginning with a \, that indicates that the file is unique to the current working directory. This is probably what is happening, but the Jasper code is not expecting it, and so ends up creating temporary files at the root of the filesystem. http://msdn.microsoft.com/en-us/library/hs3e7355.aspx

2) Jasper uses temporary files when it detects that the decompressed image is going to be >16MB.