From 905834ecca8ef5404b2d78aaed30f205ee56d465 Mon Sep 17 00:00:00 2001 From: Michael Ow Date: Sun, 21 Jun 2009 18:46:42 +0000 Subject: [PATCH] ICU-6955 Fix CharsetSCSU error and add test case. X-SVN-Rev: 26137 --- icu4c/source/test/testdata/conversion.txt | 7 ++++++ .../src/com/ibm/icu/charset/CharsetSCSU.java | 5 ++-- icu4j/main/shared/data/testdata.jar | 4 ++-- .../ibm/icu/dev/test/charset/TestCharset.java | 23 ++++++++++--------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/icu4c/source/test/testdata/conversion.txt b/icu4c/source/test/testdata/conversion.txt index 7f62e261d31..bae630d9b07 100644 --- a/icu4c/source/test/testdata/conversion.txt +++ b/icu4c/source/test/testdata/conversion.txt @@ -857,6 +857,13 @@ conversion:table(nofallback) { :intvector{}, :int{1}, :int{0}, "", ".", :bin{""} } + { + "SCSU", + :bin{ 1b9a1b541bb2411bfd1b0041 }, + "", + :intvector{}, + :int{1}, :int{0}, "", ".", :bin{""} + } } } diff --git a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetSCSU.java b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetSCSU.java index e9b24acbeff..9ac0c42e19d 100644 --- a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetSCSU.java +++ b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetSCSU.java @@ -58,7 +58,7 @@ class CharsetSCSU extends CharsetICU{ /* values between reservedStart and fixedThreshold are reserved */ private static final int reservedStart=0xA8; /* use table of predefined fixed offsets for values from fixedThreshold */ - private static final int fixedThreshold=0xF; + private static final int fixedThreshold=0xF9; //}; protected byte[] fromUSubstitution = new byte[]{(byte)0x0E,(byte)0xFF, (byte)0xFD}; @@ -325,7 +325,6 @@ class CharsetSCSU extends CharsetICU{ charErrorBufferLength = 1; label = EndLoop; cr = CoderResult.OVERFLOW; - LabelLoop = false; return label; } } @@ -488,7 +487,7 @@ class CharsetSCSU extends CharsetICU{ return label; }else if(b=fixedThreshold){ data.toUDynamicOffsets[dynamicWindow] = fixedOffsets[b-fixedThreshold]; diff --git a/icu4j/main/shared/data/testdata.jar b/icu4j/main/shared/data/testdata.jar index b696141a274..90c4c084c33 100755 --- a/icu4j/main/shared/data/testdata.jar +++ b/icu4j/main/shared/data/testdata.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:64afad09d989cb4175ee8cac27bc635053264d550b8369a6feeafca713dc2dda -size 772407 +oid sha256:d8e824c842e59c326c65665a7e9f26ec7c7c4c8aa1cec2bde603fb8f27371184 +size 772451 diff --git a/icu4j/main/tests/charset/src/com/ibm/icu/dev/test/charset/TestCharset.java b/icu4j/main/tests/charset/src/com/ibm/icu/dev/test/charset/TestCharset.java index 322157fd73f..59e413337d4 100644 --- a/icu4j/main/tests/charset/src/com/ibm/icu/dev/test/charset/TestCharset.java +++ b/icu4j/main/tests/charset/src/com/ibm/icu/dev/test/charset/TestCharset.java @@ -5320,17 +5320,18 @@ public class TestCharset extends TestFmwk { } // Test overflow buffer { - byte[] testOverflow = { - 0x41,(byte) 0xdf, 0x12,(byte) 0x81, 0x03, 0x5f, 0x10, (byte)0xdf, 0x1b, 0x03, - (byte)0xdf, 0x1c,(byte) 0x88,(byte) 0x80, 0x0b, (byte)0xbf,(byte) 0xff,(byte) 0xff - }; - decode.reset(); - try { - smBufDecode(decode, "SCSU overflow test", ByteBuffer.wrap(testOverflow), CharBuffer.allocate(8), true, true); - errln("Buffer overflow exception should have been thrown."); - } catch (BufferOverflowException ex) { - } catch (Exception ex) { - errln("Buffer overflow exception should have been thrown."); + ByteBuffer overflowTest = ByteBuffer.wrap(allFeaturesSCSU); + int sizes[] = { 8, 2, 11 }; + for (int i = 0; i < sizes.length; i++) { + try { + decode.reset(); + overflowTest.position(0); + smBufDecode(decode, "SCSU overflow test", overflowTest, CharBuffer.allocate(sizes[i]), true, false); + errln("Buffer overflow exception should have been thrown."); + } catch (BufferOverflowException ex) { + } catch (Exception ex) { + errln("Buffer overflow exception should have been thrown."); + } } }