Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6636363
Votes 0
Synopsis BufferUnderflowException decoding length 6 UTF-8 sequences with direct buffers
Category java:char_encodings
Reported Against
Release Fixed 7(b27)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs
Submit Date 01-DEC-2007
Description
Decoding the sequence
fd 93 a8 8c b9
with the charset UTF-8 with direct buffers gives

java.nio.BufferUnderflowException
	at java.nio.Buffer.nextGetIndex(Buffer.java:492)
	at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:223)
	at  xxxxx .nio.cs.UTF_8$Decoder.decodeBufferLoop(UTF_8.java:339)
	at  xxxxx .nio.cs.UTF_8$Decoder.decodeLoop(UTF_8.java:378)
	at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:562)
Posted Date : 2007-12-01 18:53:53.0
Work Around
N/A
Evaluation
Yes.  Here's the trivial fix to UTF_8.java:

@@ -322,15 +593,15 @@
 				  ((b4 & 0x3f) << 06) |
 				  ((b5 & 0x3f) << 00));
 			    n = 5;
 			    break;
 
 			case 12: case 13:
 			    // 6 bytes, 31 bits
-			    if (src.remaining() < 4)
+			    if (src.remaining() < 5)
 				return CoderResult.UNDERFLOW;
 			    if (!isContinuation(b2 = src.get()))
 				return CoderResult.malformedForLength(1);
 			    if (!isContinuation(b3 = src.get()))
 				return CoderResult.malformedForLength(2);
 			    if (!isContinuation(b4 = src.get()))
 				return CoderResult.malformedForLength(3);
Posted Date : 2007-12-01 18:53:02.0

Here's a change to the test case FindDecoderBugs.java
that checks long UTF-8 sequences.

@@ -287,21 +287,27 @@
 		System.out.printf("Testing prefix %s%n", string(prefix));
 
 	    test(prefix);
 
 	    testExhaustively(prefix, 1);
 	    testExhaustively(prefix, 2);
 	    // Can you spare a week of CPU time?
-	    // testExhaustively(cs, tester, prefix, 3);
+	    // testExhaustively(prefix, 3);
 
 	    testRandomly(prefix, 3);
 	    testRandomly(prefix, 4);
+            if (cs == utf8) {
+                testRandomly(prefix, 5);
+                testRandomly(prefix, 6);
+            }
 	}
     }
 
+    private final static Charset utf8 = Charset.forName("UTF-8");
+
     private final static Random rnd = new Random();
     private static byte randomByte() {
 	return (byte) rnd.nextInt(0x100);
     }
     private static byte[] randomBytes(int len) {
 	byte[] a = new byte[len];
 	for (int i = 0; i < len; i++)
Posted Date : 2007-12-01 18:53:02.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang