harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r678885 - /harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
Date Tue, 22 Jul 2008 20:24:50 GMT
Author: tellison
Date: Tue Jul 22 13:24:50 2008
New Revision: 678885

URL: http://svn.apache.org/viewvc?rev=678885&view=rev
Log:
Ensure UTF-8 decoder throws MalformedInputException on invalid byte sequences.
Include boundary case of 0x7F which should only be encoded in a single octet.

Modified:
    harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java

Modified: harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java?rev=678885&r1=678884&r2=678885&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
Tue Jul 22 13:24:50 2008
@@ -149,6 +149,12 @@
                             jchar = (jchar << 6) + nextByte;
                         }
                         jchar -= remainingNumbers[tail];
+                        if (jchar == 0x7F) {
+                            // U+007F should have been encoded in a single octet
+                            in.position(inIndex - in.arrayOffset());
+                            out.position(outIndex - out.arrayOffset());
+                            return CoderResult.malformedForLength(1);
+                        }
                         inIndex += tail;
                     }
                     cArr[outIndex++] = (char) jchar;
@@ -186,6 +192,10 @@
                                 jchar = (jchar << 6) + nextByte;
                             }
                             jchar -= remainingNumbers[tail];
+                            if (jchar == 0x7F) {
+                                // U+007F should have been encoded in a single octet
+                                return CoderResult.malformedForLength(1);
+                            }
                             pos += tail;
                         }
                         pos++;



Mime
View raw message