Author: markt
Date: Mon Mar 4 11:24:49 2013
New Revision: 1452256
URL: http://svn.apache.org/r1452256
Log:
Add test from unicode 6.2, chapter 3, table 3-8
Tomcat's decoder needs to check bytes in the range 80..BF start 10xx xxxx
rather than 1xxx xxxx
Modified:
tomcat/trunk/java/org/apache/tomcat/util/buf/Utf8Decoder.java
tomcat/trunk/test/org/apache/tomcat/util/buf/TestUtf8Extended.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/Utf8Decoder.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/Utf8Decoder.java?rev=1452256&r1=1452255&r2=1452256&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/Utf8Decoder.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/Utf8Decoder.java Mon Mar 4
11:24:49 2013
@@ -174,7 +174,7 @@ public class Utf8Decoder extends Charset
if (tailAvailable > 0) {
// First byte C2..DF, second byte 80..BF
if (jchar > 0x41 && jchar < 0x60 &&
- (bArr[inIndex + 1] & 0x80) != 0x80) {
+ (bArr[inIndex + 1] & 0xC0) != 0x80) {
in.position(inIndex - in.arrayOffset());
out.position(outIndex - out.arrayOffset());
return CoderResult.malformedForLength(1);
@@ -187,7 +187,7 @@ public class Utf8Decoder extends Charset
}
// First byte E1..EC, second byte 80..BF
if (jchar > 0x60 && jchar < 0x6D &&
- (bArr[inIndex + 1] & 0x80) != 0x80) {
+ (bArr[inIndex + 1] & 0xC0) != 0x80) {
in.position(inIndex - in.arrayOffset());
out.position(outIndex - out.arrayOffset());
return CoderResult.malformedForLength(1);
@@ -200,7 +200,7 @@ public class Utf8Decoder extends Charset
}
// First byte EE..EF, second byte 80..BF
if (jchar > 0x6D && jchar < 0x70 &&
- (bArr[inIndex + 1] & 0x80) != 0x80) {
+ (bArr[inIndex + 1] & 0xC0) != 0x80) {
in.position(inIndex - in.arrayOffset());
out.position(outIndex - out.arrayOffset());
return CoderResult.malformedForLength(1);
@@ -215,7 +215,7 @@ public class Utf8Decoder extends Charset
}
// First byte F1..F3, second byte 80..BF
if (jchar > 0x70 && jchar < 0x74 &&
- (bArr[inIndex + 1] & 0x80) != 0x80) {
+ (bArr[inIndex + 1] & 0xC0) != 0x80) {
in.position(inIndex - in.arrayOffset());
out.position(outIndex - out.arrayOffset());
return CoderResult.malformedForLength(1);
@@ -230,7 +230,7 @@ public class Utf8Decoder extends Charset
}
// Check third byte if present and expected
if (tailAvailable > 1 && tail > 1) {
- if ((bArr[inIndex + 2] & 0x80) != 0x80) {
+ if ((bArr[inIndex + 2] & 0xC0) != 0x80) {
in.position(inIndex - in.arrayOffset());
out.position(outIndex - out.arrayOffset());
return CoderResult.malformedForLength(2);
@@ -238,7 +238,7 @@ public class Utf8Decoder extends Charset
}
// Check fourth byte if present and expected
if (tailAvailable > 2 && tail > 2) {
- if ((bArr[inIndex + 3] & 0x80) != 0x80) {
+ if ((bArr[inIndex + 3] & 0xC0) != 0x80) {
in.position(inIndex - in.arrayOffset());
out.position(outIndex - out.arrayOffset());
return CoderResult.malformedForLength(3);
Modified: tomcat/trunk/test/org/apache/tomcat/util/buf/TestUtf8Extended.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/buf/TestUtf8Extended.java?rev=1452256&r1=1452255&r2=1452256&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/buf/TestUtf8Extended.java
(original)
+++ tomcat/trunk/test/org/apache/tomcat/util/buf/TestUtf8Extended.java Mon Mar
4 11:24:49 2013
@@ -53,6 +53,7 @@ public class TestUtf8Extended {
@Before
public void setup() {
+ /*
testCases.add(new Utf8TestCase(
"Zero length input",
new int[] {},
@@ -127,6 +128,13 @@ public class TestUtf8Extended {
new int[] {0x41, 0x80, 0x41},
1,
"A\uFFFDA"));
+ */
+ testCases.add(new Utf8TestCase(
+ "Invalid sequence from unicode 6.2 spec, table 3-8",
+ new int[] {0x61, 0xF1, 0x80, 0x80, 0xE1, 0x80, 0xC2, 0x62,
0x80,
+ 0x63, 0x80, 0xBF, 0x64},
+ 4,
+ "a\uFFFD\uFFFD\uFFFDb\uFFFDc\uFFFD\uFFFDd"));
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]