changeset 346:dde230f3536a

PR898: signed applications with big jnlp-file doesn't start
author Omair Majid <omajid@redhat.com>
date Wed, 09 May 2012 16:09:00 -0400
parents 79b3ded39c1f
children c95fe178d33d
files ChangeLog NEWS netx/net/sourceforge/jnlp/JNLPMatcher.java tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java
diffstat 4 files changed, 59 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 05 12:52:17 2012 +0200
+++ b/ChangeLog	Wed May 09 16:09:00 2012 -0400
@@ -1,3 +1,14 @@
+2012-05-09  Omair Majid  <omajid@redhat.com>
+
+	* tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java
+	(testIsMatchDoesNotHangOnLargeData): New method.
+
+2012-05-09  Lars Herschke  <lhersch@dssgmbh.de>
+
+	PR898: signed applications with big jnlp-file doesn't start
+	* netx/net/sourceforge/jnlp/JNLPMatcher.java (JNLPMatcher): Handle large
+	files correctly.
+
 2012-04-05  Jiri Vanek <jvanek@redhat.com>
 
 	Fixing issue when process was not launched at all and when was killed but
--- a/NEWS	Thu Apr 05 12:52:17 2012 +0200
+++ b/NEWS	Wed May 09 16:09:00 2012 -0400
@@ -9,6 +9,8 @@
 CVE-XXXX-YYYY: http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=XXXX-YYYY
 
 New in release 1.2.1 (2012-XX-XX):
+* NetX
+  - PR898: signed applications with big jnlp-file doesn't start (webstart affect like "frozen")
 * Plugin
   - PR895: IcedTea-Web searches for missing classes on each loadClass or findClass
 
--- a/netx/net/sourceforge/jnlp/JNLPMatcher.java	Thu Apr 05 12:52:17 2012 +0200
+++ b/netx/net/sourceforge/jnlp/JNLPMatcher.java	Wed May 09 16:09:00 2012 -0400
@@ -38,11 +38,12 @@
 package net.sourceforge.jnlp;
 
 import java.util.List;
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedList;
@@ -75,7 +76,7 @@
      *             if IOException, XMLParseException is thrown during parsing;
      *             Or launchJNLP/appTemplate is null
      */
-    public JNLPMatcher(InputStreamReader appTemplate, InputStreamReader launchJNLP,
+    public JNLPMatcher(Reader appTemplate, Reader launchJNLP,
             boolean isTemplate) throws JNLPMatcherException {
 
         if (appTemplate == null && launchJNLP == null)
@@ -87,29 +88,25 @@
             throw new JNLPMatcherException("Launching JNLP file is null.");
         
         //Declare variables for signed JNLP file
-        PipedInputStream pinTemplate= null;
-        PipedOutputStream poutTemplate= null;
+        ByteArrayOutputStream poutTemplate= null;
       
         //Declare variables for launching JNLP file 
-        PipedInputStream pinJNLPFile = null; 
-        PipedOutputStream poutJNLPFile = null; 
+        ByteArrayOutputStream poutJNLPFile = null;
         
         try {
             XMLElement appTemplateXML = new XMLElement();
             XMLElement launchJNLPXML = new XMLElement();
 
             // Remove the comments and CDATA from the JNLP file
-            pinTemplate = new PipedInputStream();
-            poutTemplate = new PipedOutputStream(pinTemplate);
+            poutTemplate = new ByteArrayOutputStream();
             appTemplateXML.sanitizeInput(appTemplate, poutTemplate);
 
-            pinJNLPFile = new PipedInputStream();
-            poutJNLPFile = new PipedOutputStream(pinJNLPFile);
+            poutJNLPFile = new ByteArrayOutputStream();
             launchJNLPXML.sanitizeInput(launchJNLP, poutJNLPFile);
 
             // Parse both files
-            appTemplateXML.parseFromReader(new InputStreamReader(pinTemplate));
-            launchJNLPXML.parseFromReader(new InputStreamReader(pinJNLPFile));
+            appTemplateXML.parseFromReader(new StringReader(poutTemplate.toString()));
+            launchJNLPXML.parseFromReader(new StringReader(poutJNLPFile.toString()));
 
             // Initialize parent nodes
             this.appTemplateNode = new Node(appTemplateXML);
@@ -122,10 +119,8 @@
                     e);
         } finally {
             // Close all stream
-            closeInputStream(pinTemplate);
             closeOutputStream(poutTemplate);
             
-            closeInputStream(pinJNLPFile);
             closeOutputStream(poutJNLPFile);
 
         }
--- a/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java	Thu Apr 05 12:52:17 2012 +0200
+++ b/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java	Wed May 09 16:09:00 2012 -0400
@@ -37,12 +37,13 @@
 
 package net.sourceforge.jnlp;
 
-import static org.junit.Assert.fail;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import junit.framework.Assert;
+import java.io.StringReader;
+import java.util.Random;
+
+import org.junit.Assert;
 import org.junit.Test;
 
 public class JNLPMatcherTest {
@@ -461,4 +462,36 @@
         fileReader.close();
         launchReader.close();
     }
+
+    @Test (timeout=1000 /*ms*/)
+    public void testIsMatchDoesNotHangOnLargeData() throws JNLPMatcherException {
+        /* construct an alphabet containing characters 'a' to 'z' */
+        final int ALPHABET_SIZE = 26;
+        char[] alphabet = new char[ALPHABET_SIZE];
+        for (int i = 0; i < ALPHABET_SIZE; i++) {
+            alphabet[i] = (char)('a' + i);
+        }
+        /* generate a long but random string using the alphabet */
+        final Random r = new Random();
+        final int STRING_SIZE = 1024 * 1024; // 1 MB
+        StringBuilder descriptionBuilder = new StringBuilder(STRING_SIZE);
+        for (int i = 0; i < STRING_SIZE; i++) {
+            descriptionBuilder.append(alphabet[r.nextInt(ALPHABET_SIZE)]);
+        }
+        String longDescription = descriptionBuilder.toString();
+
+        String file =
+                "<jnlp>\n" +
+                "  <information>\n" +
+                "    <title>JNLPMatcher hanges on large file size</title>\n" +
+                "    <vendor>IcedTea</vendor>\n" +
+                "    <description>" + longDescription + "</description>\n" +
+                "  </information>\n" +
+                "</jnlp>\n";
+
+        StringReader reader1 = new StringReader(file);
+        StringReader reader2 = new StringReader(file);
+        JNLPMatcher matcher = new JNLPMatcher(reader1, reader2, false);
+        Assert.assertTrue(matcher.isMatch());
+    }
 }