Bug 1108 - IOUtil.getTempDir(..): Difficulties to determine executable access permission on Windows via BATCH file execution
Summary: IOUtil.getTempDir(..): Difficulties to determine executable access permission...
Status: RESOLVED FIXED
Alias: None
Product: Gluegen
Classification: JogAmp
Component: core (show other bugs)
Version: 2.3.0
Hardware: All windows
: --- normal
Assignee: Sven Gothel
URL:
: 1103 (view as bug list)
Depends on:
Blocks: 1015 1109 1219
  Show dependency treegraph
 
Reported: 2014-12-11 17:53 CET by Sven Gothel
Modified: 2019-03-29 17:54 CET (History)
3 users (show)

See Also:
Type: DEFECT
SCM Refs:
150ea4f231c9629ef9ef354e3f1a92a516d46f91 181dc8ae227cd5cbecf60ab8d973bb8eef7c45f0 cb5f02b05b97dc05a3f7d4d3e3821e1fc3ae2c59
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Gothel 2014-12-11 17:53:11 CET
IOUtil.getTempDir(..) has difficulties to determine executable access permission on Windows via BATCH file execution.

IOUtil.getTempDir(..) produces the Windows error at CreateProcess 'error=2, The system cannot find the file specified'.

Log file of one user (not reproducible here):

 NativeLibrary.findLibrary(<java>, sun.misc.Launcher$AppClassLoader@b6be7ee) (CL): null
 getJarURI Default jar:file:/C:/Program%20Files/AAA/BBB/java/jarext/gluegen-rt.jar!/com/jogamp/common/os/Platform.class
 	-> jar:file:/C:/Program%20Files/AAA/BBB/java/jarext/gluegen-rt.jar!/com/jogamp/common/os/Platform.class
 getJarURI res: com.jogamp.common.os.Platform -> jar:file:/C:/Program%20Files/AAA/BBB/java/jarext/gluegen-rt.jar!/com/jogamp/common/os/Platform.class -> jar:file:/C:/Program%20Files/AAA/BBB/java/jarext/gluegen-rt.jar!/com/jogamp/common/os/Platform.class
 IOUtil.getTempRoot(): tempX1 <C:\Users\lala\AppData\Local\Temp>, used true
 IOUtil.getTempRoot(): tempX3 <C:\Users\lala\AppData\Local\Temp>, used false
 IOUtil.getTempRoot(): tempX4 <C:\Users\lala>, used true
 IOUtil.getTempRoot(): tempX2 <null>, used false
 IOUtil.testDirExec: <C:\Users\lala\AppData\Local\Temp\jogamp_exe_tst475078311489311403.bat>: Caught IOException: Cannot run program "C:\Users\lala\AppData\Local\Temp\jogamp_exe_tst475078311489311403.bat": CreateProcess error=2, The system cannot find the file specified
 IOUtil.testDirExec(): <C:\Users\lala\AppData\Local\Temp>: res -2
 IOUtil.testDirExec(): total 10ms, create 0ms, execute 10ms
 IOUtil.testDirImpl(tempX1): <C:\Users\lala\AppData\Local\Temp>, create true, exec true: false

Triage:

'C:\Users\lala\AppData\Local\Temp\jogamp_exe_tst475078311489311403.bat'

- The exec test file contains no spaces.
  Even w/ spaces it should work since patch Bug 1067 
  has been applied to master and v2.2.2:
  'Bug 1067 - IOUtil.testDirExec(File) needs to preserve SPACE 
   in exetst.getCanonicalPath() command'

- Error 'CreateProcess error=2, The system cannot find the file specified'
  - Java 'Runtime.getRuntime().exec(new String[] { "a.bat" } );' causes error:
    - Windows error: 2
    - Windows message: 'The system cannot find the file specified'
    - See <http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx>

While browsing through stackoverflow .. there is one alternative:
  - Java 'Runtime.getRuntime().exec(new String[] { "cmd", "/c", "a.bat" } );'

Solution:

Try using explicit call to Windows 'cmd.exe' w/ referencing the BATCH file location.
Comment 1 Sven Gothel 2014-12-11 19:06:09 CET
150ea4f231c9629ef9ef354e3f1a92a516d46f91

    Try using explicit call to Windows 'cmd.exe' w/ referencing the BATCH file location,
    via
      'Runtime.getRuntime().exec(new String[] { "cmd", "/c", "a.bat" } );'
    
    While the bug itself could not be reproduced here,
    I could test on Windows 7 (64bit and 32bit), as well as an WindowsXP 32bit
    that no regression occured.
Comment 2 Sven Gothel 2014-12-11 19:11:45 CET
(In reply to comment #1)
> 150ea4f231c9629ef9ef354e3f1a92a516d46f91
> 
>     Try using explicit call to Windows 'cmd.exe' w/ referencing the BATCH
> file location,
>     via
>       'Runtime.getRuntime().exec(new String[] { "cmd", "/c", "a.bat" } );'
>     
>     While the bug itself could not be reproduced here,
>     I could test on Windows 7 (64bit and 32bit), as well as an WindowsXP
> 32bit
>     that no regression occured.

TODO: Validate whether this modified exec test
still detects the execution permission restriction
as described in Bug 1015 <https://jogamp.org/bugzilla/show_bug.cgi?id=1015>.
Comment 3 Sven Gothel 2014-12-12 00:46:33 CET
(In reply to comment #2)
> TODO: Validate whether this modified exec test
> still detects the execution permission restriction
> as described in Bug 1015 <https://jogamp.org/bugzilla/show_bug.cgi?id=1015>.

Adding the software restriction as described in Bug 1015 comment 2
on path 'C:\Documents and Settings\sven\temp-noexec'
leads to proper no-exec detection:
  IOUtil.testDirImpl(tempX1): <C:\Documents and Settings\sven\temp-noexec>, create true, exec true: false

^^ Leads to use the home folder 'C:\Users\sven\'

Using the unrestricted exec path 'C:\Documents and Settings\sven\temp-exec'
still works.

Hence the 'cmd /c a.bat' batch file execution is still
restricted by software restrictions, no regression here.
Comment 4 Sven Gothel 2014-12-12 01:38:11 CET
(In reply to comment #3)
> Using the unrestricted exec path 'C:\Documents and Settings\sven\temp-exec'
> still works.
> 
> Hence the 'cmd /c a.bat' batch file execution is still
> restricted by software restrictions, no regression here.

Setting up a directory 'C:\Users\sven\temp-noexec2'
via ACLs (Advanced Security Settings), 
i.e. deny "Traverse Folder / Execute File" permissions
does _not_ work w/ this 'cmd /c a.bat' batch file exec test.

See Bug 1015 comment 3!
Comment 5 Sven Gothel 2014-12-12 01:57:40 CET
(In reply to comment #4)
> Setting up a directory 'C:\Users\sven\temp-noexec2'
> via ACLs (Advanced Security Settings), 
> i.e. deny "Traverse Folder / Execute File" permissions
> does _not_ work w/ this 'cmd /c a.bat' batch file exec test.

But it works w/ the simple 'a.bat' exec test:

+++

IOUtil.getTempRoot(): tempX1 <C:\Documents and Settings\sven\temp-noexec2>, used true
IOUtil.getTempRoot(): tempX3 <C:\Documents and Settings\sven\temp-noexec2>, used false
IOUtil.getTempRoot(): tempX4 <C:\Users\sven>, used true
IOUtil.getTempRoot(): tempX2 <null>, used false
IOUtil.testDirExec: <C:\Documents and Settings\sven\temp-noexec2\jogamp_exe_tst6314597605367855228.bat>: Caught IOException: Cannot run program "C:\Documents and Settings\sven\temp-noexec2\jogamp_exe_tst6314597605367855228.bat": CreateProcess error=5, Access is denied
IOUtil.testDirExec(): <C:\Documents and Settings\sven\temp-noexec2>: res -2
IOUtil.testDirExec(): total 125ms, create 109ms, execute 16ms
IOUtil.testDirImpl(tempX1): <C:\Documents and Settings\sven\temp-noexec2>, create true, exec true: false

+++

Hence we need to figure out how to test .. or why 
'a.bat' doesn't work on some machines.

Note above log snippet shows a different behavior, 
i.e. exposes a different error (error 5) than this bugs original (error 2)!

Here, error 5 is as expected!
Comment 6 Sven Gothel 2014-12-13 06:40:39 CET
181dc8ae227cd5cbecf60ab8d973bb8eef7c45f0

    Batch file execution test via direct call, i.e.'a.bat',
    does not work on some Windows machine, not reproducible here!
    
    A workaround would be to call the batch file explicit via 'CMD /c a.bat':
      - works when using 'Software Restriction Policies' (Bug 1015 Comment 2)
      - does _not_ work when denying ACL "Traverse Folder / Execute File" permission (Bug 1015 Comment 3)
    
    Due to this bug, we need to use a native execution:
    
    - Performing executable test w/ native exe file instead of batch file
      on Windows x86 32bit and 64bit,
    
    - using [1] TinyPE XP-W8 Compatible - x86 32bit and 64bit - 268 bytes
      - Tested on: WinXP-32bit, Win7-64bit and Win8-64bit
      - Author/License: Ange Albertini, BSD Licence, 2010-2013
    
    - On all other Windows machines (ARM, ..),
      we still use direct execution of 'a.bat'
      but may add native exe files for missing platforms.
    
    +++
    
    This patch injects said binaries within the java jar file
    and copies it into the 'to be tested' temp folder for execution.
    
    [1] TinyPE XP-W8 Compatible - x86 32bit and 64bit - 268 bytes
    is included within 'src/native/tinype-corkami',
    build manually and imported as 'src/java/com/jogamp/common/util/bin/exe-windows-i586-268b.bin'.
    
    +++
Comment 7 Sven Gothel 2014-12-13 16:18:09 CET
(In reply to comment #6)
> 181dc8ae227cd5cbecf60ab8d973bb8eef7c45f0

Backported to b22x, commit cb5f02b05b97dc05a3f7d4d3e3821e1fc3ae2c59
Comment 8 Sven Gothel 2015-01-23 01:08:54 CET
*** Bug 1103 has been marked as a duplicate of this bug. ***
Comment 9 Julien Gouesse 2015-08-17 16:10:50 CEST
I can just confirm that when exe-windows-i586-268b.bin is missing, I get this kind of exception under Windows 8.1:
java.io.IOException: Could not determine a temporary executable directory
	at com.jogamp.common.util.IOUtil.getTempDir(IOUtil.java:1168)
	at com.jogamp.common.util.cache.TempFileCache.<clinit>(TempFileCache.java:80)
	at com.jogamp.common.util.cache.TempJarCache.initSingleton(TempJarCache.java:88)
	at com.jogamp.common.os.Platform$1.run(Platform.java:309)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.jogamp.common.os.Platform.<clinit>(Platform.java:287)
	at com.jogamp.opengl.GLProfile.<clinit>(GLProfile.java:146)

When putting it into my fat JARs, it works anew. I tested with OpenJDK 1.7 update 60 and Oracle Java 1.8 update 45 both with an applet and an application.
Comment 10 Sven Gothel 2015-09-16 18:06:23 CEST
(In reply to Julien Gouesse from comment #9)
> I can just confirm that when exe-windows-i586-268b.bin is missing, I get
> this kind of exception under Windows 8.1:

You are saying that 'exe-windows-i586-268b.bin' is missing
in the fat jar?

See below .. its in the latest fat-jar ..
+++

<http://jogamp.org/deployment/archive/master/gluegen_888-joal_614-jogl_1438-jocl_1083-signed/>


unzip -l jogamp-fat.jar | grep \.bin
        0  2015-09-15 17:05   com/jogamp/common/util/bin/
      268  2015-09-15 07:59   com/jogamp/common/util/bin/exe-windows-i586-268b.bin

+++
Comment 11 Julien Gouesse 2015-09-16 19:38:59 CEST
It was missing from my own fat JAR, sorry for the confusion.