author | martin |
Thu, 30 Oct 2014 07:30:33 -0700 | |
changeset 27299 | 9055eec8eef6 |
permissions | -rw-r--r-- |
27299
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
1 |
/* |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
2 |
* Copyright 2014 Google, Inc. All Rights Reserved. |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
4 |
* |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
8 |
* |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
13 |
* accompanied this code). |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
14 |
* |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
18 |
* |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
21 |
* questions. |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
22 |
*/ |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
23 |
|
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
24 |
package parse.jdk7156085; |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
25 |
|
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
26 |
import java.io.ByteArrayInputStream; |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
27 |
import java.io.IOException; |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
28 |
import javax.xml.parsers.SAXParser; |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
29 |
import javax.xml.parsers.SAXParserFactory; |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
30 |
import org.xml.sax.InputSource; |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
31 |
import org.xml.sax.helpers.DefaultHandler; |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
32 |
import org.testng.annotations.Test; |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
33 |
|
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
34 |
/** |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
35 |
* JDK-7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
36 |
* https://bugs.openjdk.java.net/browse/JDK-7156085 |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
37 |
* |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
38 |
* XERCESJ-1257: buffer overflow in UTF8Reader for characters out of BMP |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
39 |
* https://issues.apache.org/jira/browse/XERCESJ-1257 |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
40 |
*/ |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
41 |
public class UTF8ReaderBug { |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
42 |
@Test |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
43 |
public void shouldAcceptSupplementaryCharacters() throws Throwable { |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
44 |
StringBuilder b = new StringBuilder("<xml>"); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
45 |
for(int i = 5; i < 8223; i++) { |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
46 |
b.append(' '); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
47 |
} |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
48 |
// Add surrogate characters which overflow the buffer. This shows the need to place an |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
49 |
// overflow check at -- |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
50 |
// com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:544) |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
51 |
b.append("\uD835\uDC37"); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
52 |
b.append("</xml>"); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
53 |
sendToParser(b.toString()); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
54 |
} |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
55 |
|
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
56 |
private static void sendToParser(String b) throws Throwable { |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
57 |
byte[] input = b.getBytes("UTF-8"); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
58 |
ByteArrayInputStream in = new ByteArrayInputStream(input); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
59 |
|
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
60 |
SAXParserFactory spf = SAXParserFactory.newInstance(); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
61 |
SAXParser p = spf.newSAXParser(); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
62 |
p.parse(new InputSource(in), new DefaultHandler()); |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
63 |
} |
9055eec8eef6
7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
martin
parents:
diff
changeset
|
64 |
} |