# HG changeset patch # User Deepak Bhole # Date 1311275614 14400 # Node ID f9c1a27fada92aeda5308f65e889e21afc2e7ac4 # Parent ed8d0139b60bbc2f80d20eca321191445a4da285 PR749: sun.applet.PluginStreamHandler#handleMessage(String) really slow Patch from: Ricardo Mart?n Camarero (Ricky) diff -r ed8d0139b60b -r f9c1a27fada9 AUTHORS --- 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 Deepak Bhole +Ricardo Martín Camarero Thomas Fitzsimmons Mark Greenwood Andrew John Hughes diff -r ed8d0139b60b -r f9c1a27fada9 ChangeLog --- 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 + + PR749: sun.applet.PluginStreamHandler#handleMessage(String) really slow + Patch from: Ricardo Martín Camarero (Ricky) + * 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 * configure.ac: Prepare for 1.1.2 diff -r ed8d0139b60b -r f9c1a27fada9 NEWS --- 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: diff -r ed8d0139b60b -r f9c1a27fada9 plugin/icedteanp/java/sun/applet/PluginStreamHandler.java --- 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, "\"");