/hg/icedtea-web: 3 new changesets

jvanek at icedtea.classpath.org jvanek at icedtea.classpath.org
Mon Nov 14 19:06:16 UTC 2016


changeset e03d617346ef in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=e03d617346ef
author: Jiri Vanek <jvanek at redhat.com>
date: Mon Nov 14 19:21:23 2016 +0100

	Exception from closing silent connection printed out only in debug mode. It was spamming FileNotFound exception even if the file was later found on different(valid) url

	* netx/net/sourceforge/jnlp/util/HttpUtils.java: (consumeAndCloseConnectionSilently) exception printed only in debug mode


changeset c910108cf42e in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=c910108cf42e
author: Jiri Vanek <jvanek at redhat.com>
date: Mon Nov 14 19:34:46 2016 +0100

	If port is specified in URL, it is used in cache.

	* NEWS: mentioned PR1190
	* netx/net/sourceforge/jnlp/cache/CacheUtil.java: (urlToPath) por, if used, included in path of cached resource.
	* tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java: added test (testUrlToPathWithPort) to to check port.


changeset bcc0cbd69050 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=bcc0cbd69050
author: Jiri Vanek <jvanek at redhat.com>
date: Mon Nov 14 20:11:18 2016 +0100

	Fixed PR3227. When filename in cache is to long, it is saved under its hash.

	* NEWS: mentioned PR3227
	* netx/net/sourceforge/jnlp/cache/CacheUtil.java: when resulting filename is longer then 255, then it is saved under its name hash.
	* tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java: added tests for urls with filenames longer then 255 chars.


diffstat:

 ChangeLog                                                     |  25 +++++
 NEWS                                                          |   2 +
 netx/net/sourceforge/jnlp/cache/CacheUtil.java                |  47 ++++++++++-
 netx/net/sourceforge/jnlp/util/HttpUtils.java                 |   3 +-
 tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java |  26 ++++++
 5 files changed, 101 insertions(+), 2 deletions(-)

diffs (169 lines):

diff -r 10424aa3ebd0 -r bcc0cbd69050 ChangeLog
--- a/ChangeLog	Tue Nov 08 18:11:19 2016 +0100
+++ b/ChangeLog	Mon Nov 14 20:11:18 2016 +0100
@@ -1,3 +1,28 @@
+2016-11-14  Jiri Vanek <jvanek at redhat.com>
+
+	Fixed PR3227. When filename in cache is to long, it is saved under its hash.
+	* NEWS: mentioned PR3227
+	* netx/net/sourceforge/jnlp/cache/CacheUtil.java: when resulting filename is
+	longer then 255, then it is saved under its name hash.
+	* tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java: added tests
+	for urls with filenames longer then 255 chars.
+
+2016-11-14  Jiri Vanek <jvanek at redhat.com>
+
+	If port is specified in URL, it is used in cache.
+	* NEWS: mentioned PR1190
+	* netx/net/sourceforge/jnlp/cache/CacheUtil.java: (urlToPath) por, if used,
+	included in path of cached resource.
+	* tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java: added test
+	(testUrlToPathWithPort) to to check port.
+
+2016-11-14  Jiri Vanek <jvanek at redhat.com>
+
+	Exception from closing silent connection printed out only in debug mode. It was
+	spamming FileNotFound exception even if the file was later found on different(valid) url
+	* netx/net/sourceforge/jnlp/util/HttpUtils.java: (consumeAndCloseConnectionSilently)
+	exception printed only in debug mode
+
 2016-11-08  Jiri Vanek <jvanek at redhat.com>
 
 	Fixed PR3198. ITW now tries direct socket connection when it met invalid http header by java impl.
diff -r 10424aa3ebd0 -r bcc0cbd69050 NEWS
--- a/NEWS	Tue Nov 08 18:11:19 2016 +0100
+++ b/NEWS	Mon Nov 14 20:11:18 2016 +0100
@@ -21,6 +21,8 @@
 * PR2489 - various NPEs when codebase is null
 * PR2855 - configure.ac: Remove unnecessary checks for libX11 and zlib
 * PR878 - (http-511) Handle HTTP error 511 Network Authentication Required (standard secure proxy authentification/captive portal detection) 
+* PR1190 - unuseable javaws cache handling 
+* PR3227 - can not save file with query longer then (together with name) then 255 chars 
 * comments in deployment.properties now should persists load/save
 * fixed bug in caching of files with query
 * fixed issues with recreating of existing shortcut
diff -r 10424aa3ebd0 -r bcc0cbd69050 netx/net/sourceforge/jnlp/cache/CacheUtil.java
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java	Tue Nov 08 18:11:19 2016 +0100
+++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java	Mon Nov 14 20:11:18 2016 +0100
@@ -29,6 +29,9 @@
 import java.net.URLConnection;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.security.Permission;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -480,12 +483,54 @@
         path.append(File.separatorChar);
         path.append(location.getHost());
         path.append(File.separatorChar);
+        /**
+         * This is a bit of imprecise. The usage of default port would be
+         * better, but it would cause terrible backward incompatibility.
+         */
+        if (location.getPort() > 0) {
+            path.append(location.getPort());
+            path.append(File.separatorChar);
+        }
         path.append(location.getPath().replace('/', File.separatorChar));
         if (location.getQuery() != null && !location.getQuery().trim().isEmpty()) {
             path.append(".").append(location.getQuery());
         }
 
-        return new File(FileUtils.sanitizePath(path.toString()));
+        File candidate = new File(FileUtils.sanitizePath(path.toString()));
+        if (candidate.getName().length() > 255) {
+            /**
+             * When filename is longer then 255 chars, then then various
+             * filesytems have issues to save it. By saving the file by its
+             * summ, we are trying to prevent collision of two files differs in
+             * suffixes (general suffix of name, not only 'filetype suffix')
+             * only. It is also preventing bug when truncate (files with 1000
+             * chars hash in query) cuts to much.
+             */
+            try {
+                MessageDigest md = MessageDigest.getInstance("SHA-256");
+                byte[] sum = md.digest(candidate.getName().getBytes(StandardCharsets.UTF_8));
+                //convert the byte to hex format method 2
+                StringBuilder hexString = new StringBuilder();
+                for (int i = 0; i < sum.length; i++) {
+                    hexString.append(Integer.toHexString(0xFF & sum[i]));
+                }
+                String extension = "";
+                int i = candidate.getName().lastIndexOf('.');
+                if (i > 0) {
+                    extension = candidate.getName().substring(i);//contains dot
+                }
+                if (extension.length() < 10 && extension.length() > 1) {
+                    hexString.append(extension);
+                }
+                candidate = new File(candidate.getParentFile(), hexString.toString());
+            } catch (NoSuchAlgorithmException ex) {
+                // should not occure, cite from javadoc:
+                // every java iomplementation should support
+                // MD5 SHA-1 SHA-256
+                throw new RuntimeException(ex);
+            }
+        }
+        return candidate;
     }
 
     /**
diff -r 10424aa3ebd0 -r bcc0cbd69050 netx/net/sourceforge/jnlp/util/HttpUtils.java
--- a/netx/net/sourceforge/jnlp/util/HttpUtils.java	Tue Nov 08 18:11:19 2016 +0100
+++ b/netx/net/sourceforge/jnlp/util/HttpUtils.java	Mon Nov 14 20:11:18 2016 +0100
@@ -52,7 +52,8 @@
         try {
             consumeAndCloseConnection(c);
         } catch (IOException ex) {
-            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ex);
+            OutputController.getLogger().log("Following exception: '" + ex.getMessage() + "' should be harmless, but may help in finding root cause.");
+            OutputController.getLogger().log(ex);
         }
     }
 
diff -r 10424aa3ebd0 -r bcc0cbd69050 tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java
--- a/tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java	Tue Nov 08 18:11:19 2016 +0100
+++ b/tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java	Mon Nov 14 20:11:18 2016 +0100
@@ -38,6 +38,7 @@
 
 import java.io.File;
 import java.net.URL;
+import net.sourceforge.jnlp.annotations.Bug;
 import net.sourceforge.jnlp.util.UrlUtils;
 
 import org.junit.Assert;
@@ -62,6 +63,31 @@
         final File expected = new File("/tmp/https/example.com/applet/some_weird_applet..jar");
         Assert.assertEquals(expected, CacheUtil.urlToPath(u, "/tmp"));
     }
+
+    @Test
+    @Bug(id = "1190")
+    public void testUrlToPathWithPort() throws Exception {
+        final URL u = new URL("https://example.com:5050/applet/some:weird*applet?.jar");
+        //stuf behind querry is kept
+        final File expected = new File("/tmp/https/example.com/5050/applet/some_weird_applet..jar");
+        Assert.assertEquals(expected, CacheUtil.urlToPath(u, "/tmp"));
+    }
+
+    @Test
+    @Bug(id = "3227")
+    public void testUrlToPathLonger256() throws Exception {
+        final URL u = new URL("https://example.com:5050/applet/uspto-auth.authenticate.jnlp.q_SlNFU1NJT05JRD02OUY1ODVCNkJBOTM1NThCQjdBMTA5RkQyNDZEQjEwRi5wcm9kX3RwdG9tY2F0MjE1X2p2bTsgRW50cnVzdFRydWVQYXNzUmVkaXJlY3RVcmw9Imh0dHBzOi8vZWZzLnVzcHRvLmdvdi9FRlNXZWJVSVJlZ2lzdGVyZWQvRUZTV2ViUmVnaXN0ZXJlZCI7IFRDUFJPRFBQQUlSc2Vzc2lvbj02MjIxMjk0MTguMjA0ODAuMDAwMA__.info");
+        final File expected = new File("/tmp/https/example.com/5050/applet/a2ac35576c36d0304c86eb9e645a251ff69dba28646e13f2e81dbb9cc96097f.info");
+        Assert.assertEquals(expected, CacheUtil.urlToPath(u, "/tmp"));
+    }
+    
+    @Test
+    @Bug(id = "3227")
+    public void testUrlToPathLonger256NoSuffix() throws Exception {
+        final URL u = new URL("https://example.com:5050/applet/uspto-auth.authenticate.jnlp.q_SlNFU1NJT05JRD02OUY1ODVCNkJBOTM1NThCQjdBMTA5RkQyNDZEQjEwRi5wcm9kX3RwdG9tY2F0MjE1X2p2bTsgRW50cnVzdFRydWVQYXNzUmVkaXJlY3RVcmw9Imh0dHBzOi8vZWZzLnVzcHRvLmdvdi9FRlNXZWJVSVJlZ2lzdGVyZWQvRUZTV2ViUmVnaXN0ZXJlZCI7IFRDUFJPRFBQQUlSc2Vzc2lvbj02MjIxMjk0MTguMjA0ODAuMDAwMA");
+        final File expected = new File("/tmp/https/example.com/5050/applet/e4f3cf11f86f5aa33f424bc3efe3df7a9d20837a6f1a5bbbc60c1f57f3780a4");
+        Assert.assertEquals(expected, CacheUtil.urlToPath(u, "/tmp"));
+    }
     
     
     @Test


More information about the distro-pkg-dev mailing list