Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to check if a jar file is valid?
    primarykey
    data
    text
    <p>my webapp allows a user to upload a jar file. however, after the jar file is uploaded, it is corrupted. i have verified this by comparing the md5 checksum (winmd5free). </p> <p>the uploaded jar file looks "normal" and "right"</p> <ul> <li>the file size compared to the original looks right (at the KB level)</li> <li>i can open the uploaded jar file using 7z and view its content (resources and class files), and everything is the same compared to the original</li> </ul> <p>when i open up the uploaded jar file (using Notepad++), i did notice that the binary contents are different from the original. also, when i used JarInputStream to read the jar entries, there were no entries.</p> <pre><code>JarInputStream is = new JarInputStream(new FileInputStream(new File("uploaded.jar"))); JarEntry entry = null; while(null != (entry = is.getNextJarEntry())) { System.out.println(entry.getName()); } </code></pre> <p>furthermore, when i double click on the jar (Windows), i get the following message.</p> <blockquote> <p>Error: Invalid or corrupt jarfile</p> </blockquote> <p>my questions are</p> <ul> <li>is there a way to programmatically check if a jar file is valid? i would have expected JarInputStream to detect this right away, but it shows no problems at all</li> <li>when i double click on the jar file, in windows, is it java.exe that is giving me the invalid or corrupt jarfile message?</li> <li>how come when an invalid jar file is passed in as part of the classpath, no error/exception is thrown? e.g. <em>java -cp uploaded.jar;libs* com.some.class.Test</em> ?</li> </ul> <p>please note that this has nothing to do with jar signing and/or checking the signing of a jar. it is simply checking if a file (uploaded or not) is a valid jar file (not necessarily if the jar's class files are valid, as there is another SO post on this issue already).</p> <p>results for running </p> <blockquote> <p>jar -tvf uploaded.jar</p> </blockquote> <pre><code>java.util.zip.ZipException: error in opening zip file at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.&lt;init&gt;(ZipFile.java:127) at java.util.zip.ZipFile.&lt;init&gt;(ZipFile.java:88) at sun.tools.jar.Main.list(Main.java:977) at sun.tools.jar.Main.run(Main.java:222) at sun.tools.jar.Main.main(Main.java:1147) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload