changeset 253:f9c1a27fada9

PR749: sun.applet.PluginStreamHandler#handleMessage(String) really slow Patch from: Ricardo Mart?n Camarero (Ricky) <rickyepoderi at yahoo dot es>
author Deepak Bhole <dbhole@redhat.com>
date Thu, 21 Jul 2011 15:13:34 -0400
parents ed8d0139b60b
children db6914cf15be
files AUTHORS ChangeLog NEWS plugin/icedteanp/java/sun/applet/PluginStreamHandler.java
diffstat 4 files changed, 71 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/AUTHORS	Wed Jul 20 09:33:13 2011 -0400
+++ b/AUTHORS	Thu Jul 21 15:13:34 2011 -0400
@@ -3,6 +3,7 @@
 
 Lillian Angel <langel@redhat.com>
 Deepak Bhole <dbhole@redhat.com>
+Ricardo Martín Camarero <rickyepoderi@yahoo.es>
 Thomas Fitzsimmons <fitzsim@redhat.com>
 Mark Greenwood <mark@dcs.shef.ac.uk>
 Andrew John Hughes <gnu_andrew@member.fsf.org, ahughes@redhat.com>
--- a/ChangeLog	Wed Jul 20 09:33:13 2011 -0400
+++ b/ChangeLog	Thu Jul 21 15:13:34 2011 -0400
@@ -1,3 +1,12 @@
+2011-07-21  Deepak Bhole <dbhole@redhat.com>
+
+	PR749: sun.applet.PluginStreamHandler#handleMessage(String) really slow
+	Patch from: Ricardo Martín Camarero (Ricky) <rickyepoderi at yahoo dot es>
+	* plugin/icedteanp/java/sun/applet/PluginStreamHandler.java
+	(readPair): New function.
+	(handleMessage): Use readPair to incrementally tokenize message, rather
+	than using String.split().
+
 2011-07-20  Deepak Bhole <dbhole@redhat.com>
 
 	* configure.ac: Prepare for 1.1.2
--- a/NEWS	Wed Jul 20 09:33:13 2011 -0400
+++ b/NEWS	Thu Jul 21 15:13:34 2011 -0400
@@ -9,6 +9,8 @@
 CVE-XXXX-YYYY: http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=XXXX-YYYY
 
 New in release 1.1.2 (2011-XX-XX):
+* Plugin
+  - PR749: sun.applet.PluginStreamHandler#handleMessage(String) really slow
 
 New in release 1.1.1 (2011-07-20):
 * Security updates:
--- a/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java	Wed Jul 20 09:33:13 2011 -0400
+++ b/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java	Thu Jul 21 15:13:34 2011 -0400
@@ -113,18 +113,58 @@
         listenerThread.start();
     }
 
+    /**
+     * Given a string, reads the first two (space separated) tokens.
+     *
+     * @param message The string to read
+     * @param start The position to start reading at
+     * @param array The array into which the first two tokens are placed
+     * @return Position where the next token starts
+     */
+    private int readPair(String message, int start, String[] array) {
+        
+        int end = start;
+        array[0] = null;
+        array[1] = null;
+
+        if (message.length() > start) {
+            int firstSpace = message.indexOf(' ', start);
+            if (firstSpace == -1) {
+                array[0] = message.substring(start);
+                end = message.length();
+            } else {
+                array[0] = message.substring(start, firstSpace);
+                if (message.length() > firstSpace + 1) {
+                    int secondSpace = message.indexOf(' ', firstSpace + 1);
+                    if (secondSpace == -1) {
+                        array[1] = message.substring(firstSpace + 1);
+                        end = message.length();
+                    } else {
+                        array[1] = message.substring(firstSpace + 1, secondSpace);
+                        end = secondSpace + 1;
+                    }
+                }
+            }
+        }
+
+        PluginDebug.debug("readPair: '", array[0], "' - '", array[1], "' ", end);
+        return end;
+    }
+
     public void handleMessage(String message) throws PluginException {
 
-        int nextIndex = 0;
         int reference = -1;
         String src = null;
         String[] privileges = null;
         String rest = "";
-
-        String[] msgComponents = message.split(" ");
+        String[] msgComponents = new String[2];
+        int pos = 0;
+        int oldPos = 0;
 
-        if (msgComponents.length < 2)
+        pos = readPair(message, oldPos, msgComponents);
+        if (msgComponents[0] == null || msgComponents[1] == null) {
             return;
+        }
 
         if (msgComponents[0].startsWith("plugin")) {
             handlePluginMessage(message);
@@ -134,38 +174,38 @@
         // type and identifier are guaranteed to be there
         String type = msgComponents[0];
         final int identifier = Integer.parseInt(msgComponents[1]);
-        nextIndex = 2;
 
         // reference, src and privileges are optional components, 
         // and are guaranteed to be in that order, if they occur
+        oldPos = pos;
+        pos = readPair(message, oldPos, msgComponents);
 
         // is there a reference ?
-        if (msgComponents[nextIndex].equals("reference")) {
-            reference = Integer.parseInt(msgComponents[nextIndex + 1]);
-            nextIndex += 2;
+        if ("reference".equals(msgComponents[0])) {
+            reference = Integer.parseInt(msgComponents[1]);
+            oldPos = pos;
+            pos = readPair(message, oldPos, msgComponents);
         }
 
         // is there a src?
-        if (msgComponents[nextIndex].equals("src")) {
-            src = msgComponents[nextIndex + 1];
-            nextIndex += 2;
+        if ("src".equals(msgComponents[0])) {
+            src = msgComponents[1];
+            oldPos = pos;
+            pos = readPair(message, oldPos, msgComponents);
         }
 
         // is there a privileges?
-        if (msgComponents[nextIndex].equals("privileges")) {
-            String privs = msgComponents[nextIndex + 1];
+        if ("privileges".equals(msgComponents[0])) {
+            String privs = msgComponents[1];
             privileges = privs.split(",");
-            nextIndex += 2;
+            oldPos = pos;
         }
 
         // rest
-        for (int i = nextIndex; i < msgComponents.length; i++) {
-            rest += msgComponents[i];
-            rest += " ";
+        if (message.length() > oldPos) {
+            rest = message.substring(oldPos);
         }
 
-        rest = rest.trim();
-
         try {
 
             PluginDebug.debug("Breakdown -- type: ", type, " identifier: ", identifier, " reference: ", reference, " src: ", src, " privileges: ", privileges, " rest: \"", rest, "\"");