diff options
| author | Ito Kazumitsu <kaz@maczuka.gcd.org> | 2005-11-13 22:18:23 +0000 |
|---|---|---|
| committer | Ito Kazumitsu <kaz@maczuka.gcd.org> | 2005-11-13 22:18:23 +0000 |
| commit | c021a6305fabb7861712842ddca5534eb9a8ba89 (patch) | |
| tree | f7864d7422f1830783b0ee21f642db76f4dcee06 /gnu/java/nio/charset/UTF_16Decoder.java | |
| parent | 2c9e15cd1e6331f6465162a4f5263a4546b33dbc (diff) | |
| download | classpath-c021a6305fabb7861712842ddca5534eb9a8ba89.tar.gz | |
2005-11-13 Ito Kazumitsu <kaz@maczuka.gcd.org>
Fixes bug #23008
* gnu/java/nio/charset/UTF_16Decoder.java
MAYBE_BIG_ENDIAN, MAYBE_LITTLE_ENDIAN: New constants representing
such endianness which is similar to UNKNOWN_ENDIAN but defaults
to big/little endian without a byte order mark.
(decodeLoop): Handle MAYBE_BIG_ENDIAN and MAYBE_LITTLE_ENDIAN.
* gnu/java/nio/charset/UnicodeLittle.java
(newDecoder): Set the endianness to MAYBE_LITTLE_ENDIAN.
Diffstat (limited to 'gnu/java/nio/charset/UTF_16Decoder.java')
| -rw-r--r-- | gnu/java/nio/charset/UTF_16Decoder.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/gnu/java/nio/charset/UTF_16Decoder.java b/gnu/java/nio/charset/UTF_16Decoder.java index e3927d994..fa1dbc412 100644 --- a/gnu/java/nio/charset/UTF_16Decoder.java +++ b/gnu/java/nio/charset/UTF_16Decoder.java @@ -54,6 +54,8 @@ final class UTF_16Decoder extends CharsetDecoder static final int BIG_ENDIAN = 0; static final int LITTLE_ENDIAN = 1; static final int UNKNOWN_ENDIAN = 2; + static final int MAYBE_BIG_ENDIAN = 3; + static final int MAYBE_LITTLE_ENDIAN = 4; private static final char BYTE_ORDER_MARK = 0xFEFF; private static final char REVERSED_BYTE_ORDER_MARK = 0xFFFE; @@ -81,26 +83,37 @@ final class UTF_16Decoder extends CharsetDecoder byte b2 = in.get (); // handle byte order mark - if (byteOrder == UNKNOWN_ENDIAN) + if (byteOrder == UNKNOWN_ENDIAN || + byteOrder == MAYBE_BIG_ENDIAN || + byteOrder == MAYBE_LITTLE_ENDIAN) { char c = (char) (((b1 & 0xFF) << 8) | (b2 & 0xFF)); if (c == BYTE_ORDER_MARK) { + if (byteOrder == MAYBE_LITTLE_ENDIAN) + { + return CoderResult.malformedForLength (2); + } byteOrder = BIG_ENDIAN; inPos += 2; continue; } else if (c == REVERSED_BYTE_ORDER_MARK) { + if (byteOrder == MAYBE_BIG_ENDIAN) + { + return CoderResult.malformedForLength (2); + } byteOrder = LITTLE_ENDIAN; inPos += 2; continue; } else { - // assume big endian, do not consume bytes, + // assume big or little endian, do not consume bytes, // continue with normal processing - byteOrder = BIG_ENDIAN; + byteOrder = (byteOrder == MAYBE_LITTLE_ENDIAN ? + LITTLE_ENDIAN : BIG_ENDIAN); } } |
