<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>1108</bug_id>
          
          <creation_ts>2014-12-11 17:53:11 +0100</creation_ts>
          <short_desc>IOUtil.getTempDir(..): Difficulties to determine executable access permission on Windows via BATCH file execution</short_desc>
          <delta_ts>2019-03-29 17:54:44 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Gluegen</product>
          <component>core</component>
          <version>2.3.0</version>
          <rep_platform>All</rep_platform>
          <op_sys>windows</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>---</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>1015</blocked>
    
    <blocked>1109</blocked>
    
    <blocked>1219</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Sven Gothel">sgothel</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          <cc>askinner</cc>
    
    <cc>gouessej</cc>
    
    <cc>rene</cc>
          
          <cf_type>DEFECT</cf_type>
          <cf_scm_refs>150ea4f231c9629ef9ef354e3f1a92a516d46f91
181dc8ae227cd5cbecf60ab8d973bb8eef7c45f0
cb5f02b05b97dc05a3f7d4d3e3821e1fc3ae2c59</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>4476</commentid>
    <comment_count>0</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-12-11 17:53:11 +0100</bug_when>
    <thetext>IOUtil.getTempDir(..) has difficulties to determine executable access permission on Windows via BATCH file execution.

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

Log file of one user (not reproducible here):

 NativeLibrary.findLibrary(&lt;java&gt;, 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
 	-&gt; 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 -&gt; jar:file:/C:/Program%20Files/AAA/BBB/java/jarext/gluegen-rt.jar!/com/jogamp/common/os/Platform.class -&gt; jar:file:/C:/Program%20Files/AAA/BBB/java/jarext/gluegen-rt.jar!/com/jogamp/common/os/Platform.class
 IOUtil.getTempRoot(): tempX1 &lt;C:\Users\lala\AppData\Local\Temp&gt;, used true
 IOUtil.getTempRoot(): tempX3 &lt;C:\Users\lala\AppData\Local\Temp&gt;, used false
 IOUtil.getTempRoot(): tempX4 &lt;C:\Users\lala&gt;, used true
 IOUtil.getTempRoot(): tempX2 &lt;null&gt;, used false
 IOUtil.testDirExec: &lt;C:\Users\lala\AppData\Local\Temp\jogamp_exe_tst475078311489311403.bat&gt;: Caught IOException: Cannot run program &quot;C:\Users\lala\AppData\Local\Temp\jogamp_exe_tst475078311489311403.bat&quot;: CreateProcess error=2, The system cannot find the file specified
 IOUtil.testDirExec(): &lt;C:\Users\lala\AppData\Local\Temp&gt;: res -2
 IOUtil.testDirExec(): total 10ms, create 0ms, execute 10ms
 IOUtil.testDirImpl(tempX1): &lt;C:\Users\lala\AppData\Local\Temp&gt;, create true, exec true: false

Triage:

&apos;C:\Users\lala\AppData\Local\Temp\jogamp_exe_tst475078311489311403.bat&apos;

- 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:
  &apos;Bug 1067 - IOUtil.testDirExec(File) needs to preserve SPACE 
   in exetst.getCanonicalPath() command&apos;

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

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

Solution:

Try using explicit call to Windows &apos;cmd.exe&apos; w/ referencing the BATCH file location.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4479</commentid>
    <comment_count>1</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-12-11 19:06:09 +0100</bug_when>
    <thetext>150ea4f231c9629ef9ef354e3f1a92a516d46f91

    Try using explicit call to Windows &apos;cmd.exe&apos; w/ referencing the BATCH file location,
    via
      &apos;Runtime.getRuntime().exec(new String[] { &quot;cmd&quot;, &quot;/c&quot;, &quot;a.bat&quot; } );&apos;
    
    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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4480</commentid>
    <comment_count>2</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-12-11 19:11:45 +0100</bug_when>
    <thetext>(In reply to comment #1)
&gt; 150ea4f231c9629ef9ef354e3f1a92a516d46f91
&gt; 
&gt;     Try using explicit call to Windows &apos;cmd.exe&apos; w/ referencing the BATCH
&gt; file location,
&gt;     via
&gt;       &apos;Runtime.getRuntime().exec(new String[] { &quot;cmd&quot;, &quot;/c&quot;, &quot;a.bat&quot; } );&apos;
&gt;     
&gt;     While the bug itself could not be reproduced here,
&gt;     I could test on Windows 7 (64bit and 32bit), as well as an WindowsXP
&gt; 32bit
&gt;     that no regression occured.

TODO: Validate whether this modified exec test
still detects the execution permission restriction
as described in Bug 1015 &lt;https://jogamp.org/bugzilla/show_bug.cgi?id=1015&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4481</commentid>
    <comment_count>3</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-12-12 00:46:33 +0100</bug_when>
    <thetext>(In reply to comment #2)
&gt; TODO: Validate whether this modified exec test
&gt; still detects the execution permission restriction
&gt; as described in Bug 1015 &lt;https://jogamp.org/bugzilla/show_bug.cgi?id=1015&gt;.

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

^^ Leads to use the home folder &apos;C:\Users\sven\&apos;

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

Hence the &apos;cmd /c a.bat&apos; batch file execution is still
restricted by software restrictions, no regression here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4483</commentid>
    <comment_count>4</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-12-12 01:38:11 +0100</bug_when>
    <thetext>(In reply to comment #3)
&gt; Using the unrestricted exec path &apos;C:\Documents and Settings\sven\temp-exec&apos;
&gt; still works.
&gt; 
&gt; Hence the &apos;cmd /c a.bat&apos; batch file execution is still
&gt; restricted by software restrictions, no regression here.

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

See Bug 1015 comment 3!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4484</commentid>
    <comment_count>5</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-12-12 01:57:40 +0100</bug_when>
    <thetext>(In reply to comment #4)
&gt; Setting up a directory &apos;C:\Users\sven\temp-noexec2&apos;
&gt; via ACLs (Advanced Security Settings), 
&gt; i.e. deny &quot;Traverse Folder / Execute File&quot; permissions
&gt; does _not_ work w/ this &apos;cmd /c a.bat&apos; batch file exec test.

But it works w/ the simple &apos;a.bat&apos; exec test:

+++

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

+++

Hence we need to figure out how to test .. or why 
&apos;a.bat&apos; doesn&apos;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!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4486</commentid>
    <comment_count>6</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-12-13 06:40:39 +0100</bug_when>
    <thetext>181dc8ae227cd5cbecf60ab8d973bb8eef7c45f0

    Batch file execution test via direct call, i.e.&apos;a.bat&apos;,
    does not work on some Windows machine, not reproducible here!
    
    A workaround would be to call the batch file explicit via &apos;CMD /c a.bat&apos;:
      - works when using &apos;Software Restriction Policies&apos; (Bug 1015 Comment 2)
      - does _not_ work when denying ACL &quot;Traverse Folder / Execute File&quot; 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 &apos;a.bat&apos;
      but may add native exe files for missing platforms.
    
    +++
    
    This patch injects said binaries within the java jar file
    and copies it into the &apos;to be tested&apos; temp folder for execution.
    
    [1] TinyPE XP-W8 Compatible - x86 32bit and 64bit - 268 bytes
    is included within &apos;src/native/tinype-corkami&apos;,
    build manually and imported as &apos;src/java/com/jogamp/common/util/bin/exe-windows-i586-268b.bin&apos;.
    
    +++</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4487</commentid>
    <comment_count>7</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-12-13 16:18:09 +0100</bug_when>
    <thetext>(In reply to comment #6)
&gt; 181dc8ae227cd5cbecf60ab8d973bb8eef7c45f0

Backported to b22x, commit cb5f02b05b97dc05a3f7d4d3e3821e1fc3ae2c59</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4531</commentid>
    <comment_count>8</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2015-01-23 01:08:54 +0100</bug_when>
    <thetext>*** Bug 1103 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4942</commentid>
    <comment_count>9</comment_count>
    <who name="Julien Gouesse">gouessej</who>
    <bug_when>2015-08-17 16:10:50 +0200</bug_when>
    <thetext>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.&lt;clinit&gt;(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.&lt;clinit&gt;(Platform.java:287)
	at com.jogamp.opengl.GLProfile.&lt;clinit&gt;(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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5107</commentid>
    <comment_count>10</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2015-09-16 18:06:23 +0200</bug_when>
    <thetext>(In reply to Julien Gouesse from comment #9)
&gt; I can just confirm that when exe-windows-i586-268b.bin is missing, I get
&gt; this kind of exception under Windows 8.1:

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

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

&lt;http://jogamp.org/deployment/archive/master/gluegen_888-joal_614-jogl_1438-jocl_1083-signed/&gt;


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

+++</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5110</commentid>
    <comment_count>11</comment_count>
    <who name="Julien Gouesse">gouessej</who>
    <bug_when>2015-09-16 19:38:59 +0200</bug_when>
    <thetext>It was missing from my own fat JAR, sorry for the confusion.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>