changeset 1358:3cc8e02e66bc icedtea-2.7.0pre04

7156085, PR2674: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser Summary: improve support for supplementary characters Reviewed-by: joehw
author aefimov
date Wed, 10 Jun 2015 16:47:37 +0300
parents e3e97df49dcb
children 4b0a1c213416
files src/com/sun/org/apache/xerces/internal/impl/io/UTF8Reader.java
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/sun/org/apache/xerces/internal/impl/io/UTF8Reader.java	Sun May 31 18:54:58 2015 +0300
+++ b/src/com/sun/org/apache/xerces/internal/impl/io/UTF8Reader.java	Wed Jun 10 16:47:37 2015 +0300
@@ -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) {