7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
authormartin
Thu, 30 Oct 2014 07:24:51 -0700
changeset 27311 8f2d46041f72
parent 27236 b409bc51bc23
child 27312 1b163230e8c0
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser Summary: improve support for supplementary characters Reviewed-by: joehw
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/io/UTF8Reader.java
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/io/UTF8Reader.java	Wed Jul 05 20:05:30 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/io/UTF8Reader.java	Thu Oct 30 07:24:51 2014 -0700
@@ -529,6 +529,16 @@
                     invalidByte(4, 4, b2);
                 }
 
+                // check if output buffer is large enough to hold 2 surrogate chars
+                if (out + 1 >= ch.length) {
+                    fBuffer[0] = (byte)b0;
+                    fBuffer[1] = (byte)b1;
+                    fBuffer[2] = (byte)b2;
+                    fBuffer[3] = (byte)b3;
+                    fOffset = 4;
+                    return out - offset;
+                }
+
                 // decode bytes into surrogate characters
                 int uuuuu = ((b0 << 2) & 0x001C) | ((b1 >> 4) & 0x0003);
                 if (uuuuu > 0x10) {