History log of /libcore/luni/src/main/native/libcore_icu_NativeConverter.cpp
Revision Date Author Comments
fef459ae66f78b180f05942c9f659781c3822d07 24-Nov-2017 Neil Fuller <nfuller@google.com> Add size check in NativeConverter JNI code

Adding an addition check to avoid copying arbitrary-length
bytes/chars into a statically allocated array. In reality
this is very unlikely to happen as the encoder replacement
length is checked in Java via an if (len > maxBytesPerChar)
in all cases. The decoder replacement is either hardcoded
(and below the limit), or checked when it is set via
withReplacement().

Bug: 63876067
Test: Ran org.apache.harmony.tests.java.nio.charset.Charset.*Test
Change-Id: Id6a7c5cc05a72dc84c405fee18e3e5a0f5f6495b
4bdd5651813b17dcd895eaac9bde911126287fa5 19-Jul-2017 Zhizhou Yang <zhizhouy@google.com> Fix clang static analyzer warning in libcore

There are two potential memory leaks in
libcore/luni/src/main/native/libcore_icu_NativeConverter.cpp. The
callbackContext would not be deleted before returning if it was newly
created.

Fixed it by using an unique_ptr to manage it.

Bug: 63876067

Test: mmm with static analyzer and warning disappears. Ran CTS test for
CtsLibcoreTestCases and no new errors.

Change-Id: If700a31fe10065a67e4aa4044fa47672d1dd6a0d
cab01ac294bb8ded259851673baa4c6ca226f828 19-Jul-2017 Steven Moreland <smoreland@google.com> libcore: use proper nativehelper headers

libnativeheader exports headers under nativeheader. These were
available before incorrectly as global headers in order to give
access to jni.h.

Test: modules using libcore find headers
Bug: 63762847
Change-Id: Ic5873017bcf4d1c6e0873d7030ce56ee597b580d
c04007c41f7363f5f4cde7e19a582ac13adbc153 17-Jul-2017 Pete Gillin <peteg@google.com> Fix the byte ordering behaviour of the UTF-16 Charset.

The behavioural change here is that the UTF-16 Charset (obtained via
java.nio.charset.Charset.forName("UTF-16") or
java.nio.charset.StandardCharsets.UTF_16) now encodes Strings into
big-endian UTF-16 bytes with a byte-order marker, as the javadoc says
it does. Previously, it encoded as little-endian with a byte-order
marker. (Users wanting to encode as little-endian with a byte-order
marker can use x-UTF-16LE-BOM.)

The test changes are as follows.

CharsetTest#test_UTF_16: This was suppressed. It now passes thanks to
the above change, and we un-suppress it.

CharsetTest#test_UTF_16BE and _UTF_16LE: These were suppressed. We remove the
assertions about how it handles a reverse-BOM (i.e. a BOM with the
wrong byte order), and un-suppress them. The javadoc doesn't specify
how reverse-BOMs should be handled, so this change means we go from
not testing anything to testing the specified behaviour.

CharsetTest#test_x-UTF_16LE_BOM, _UTF_32, _UTF_32BE, UTF_32LE: These
were suppressed. The javadoc doesn't mention these, but developers
might reasonably expect them to exist and have sensible behaviour, and
they do, so we make some tweaks to the assertions and remove the
assertions about reverse-BOM-handling and un-suppress the tests. We
also remove the 'hack' which prevented it testing that UTF-32 exists,
since that doesn't seem to be needed any more.

CharsetTest#test_X_UTF_32BE_BOM, _X_UTF_32LE_BOM: These were
suppressed. We don't support these and don't expect to do so in the
foreseeable future, so we just remove the tests.

UTF16CharsetEncoderTest: Previously, this class overrode the
assertByteArray method in its superclass so that, instead of asserting
byte array equality, it just asserted that the byte arrays decoded to
the same strings. This made this test almost
endian-agnostic... although, presumably thanks to an oversight,
testDefaultValue was actually asserting that UTF-16 encodes as LE. We
remove the override and change the byte arrays so that the test now
asserts that UTF-16 encodes as BE as required.

OldCharset_MultiByte_UTF_16: This test asserts that UTF-16 encodes as
BE, and was suppressed. We un-suppress it.

OldCharset_MultiByte_UTF_16_Android: This test was a variant of the
previous one what asserted that UTF-16 encodes as LE. We remove it.

String2Test: Previously asserted that UTF-16 encodes as LE, now
correctly asserts that it encodes as BE. Also slightly strengthened
assertion.

Bug: 2702411
Fixes: 2702411
Bug: 37074504
Fixes: 37074504
Test: cts-tradefed run cts -m CtsLibcoreTestCases -a arm64-v8a
Change-Id: If174cd9ff0105008bd18a63e58ab3fa9a90c7475
37f866f8068fce60d5af005d7f3ab039c08faf08 06-Apr-2017 Fredrik Roubert <roubert@google.com> Update JNI code in preparation for ICU 59 switching to C++11 char16_t.

ICU 59 (update pending on the aosp/icu59 branch) has switched to using
the C++11 char16_t data type, which is a distinct type from uint16_t
(which is what JNI's jchar is typedef'd as), even though they are
bitwise identical.

All code that passes UTF-16 data between ICU4C and JNI must therefore be
updated with typecasts in the appropriate places before ICU 59 is merged
to aosp/master.

Bug: 37554848
Test: make
Change-Id: I10808c4104e9dabfd90975ee61c465b22ff30281
df8dc5a87fd0340b4817fac1100b8cfcf081e6b6 14-Jun-2017 Nicolas Geoffray <ngeoffray@google.com> Throw an exception if we could not open a converter.

In order to rule out the address being null in crashes such as:

dalvik.system.InMemoryDexClassLoaderTest#test_oneDexDirect_callInstanceMethod
java.lang.IllegalArgumentException: Non-positive averageBytesPerChar
at java.nio.charset.CharsetEncoder.<init>(CharsetEncoder.java:205)
at java.nio.charset.CharsetEncoderICU.<init>(CharsetEncoderICU.java:97)
at java.nio.charset.CharsetEncoderICU.newInstance(CharsetEncoderICU.java:75)

Seen here:
http://build.chromium.org/p/client.art/builders/bullhead-armv8-gcstress-ndebug/builds/1

bug: 62612946

Test: run-libcore-tests
Change-Id: Idde0b5f6a83cb7e54e9ab1f6ba22d394fb67aa18
6d8d1ea910c1ad026b48c87424da92a250664dd2 29-Sep-2016 Mark Salyzyn <salyzyn@google.com> libcore: Replace cutils/log.h with android/log.h

Test: compile
Bug: 26552300
Bug: 31289077
Change-Id: I17500b9c8262f37b5cdd3ea1d275f97346595c01
1bdc6bc1c72b033ed860360e69fc9f1f1121579b 22-Apr-2016 Narayan Kamath <narayan@google.com> CharsetEncoder/Decoder: Use NativeAllocationRegistry.

Works around issues with finalizer ordering.

bug: 26076560

(cherry picked from commit c672ce800bbc27cb79f78d9204a51ec06ef1ec3d)

Change-Id: I434842966fe2cda70aa955250162c562ce0f8991
c672ce800bbc27cb79f78d9204a51ec06ef1ec3d 22-Apr-2016 Narayan Kamath <narayan@google.com> CharsetEncoder/Decoder: Use NativeAllocationRegistry.

Works around issues with finalizer ordering.

bug: 26076560
Change-Id: I4977ff9e2f6234283bd23dfc39a574d4854f6655
8fbe7d8a9df5f464da59a2938acaf211845b89da 26-Jan-2016 Yi Kong <yikong@google.com> Check for exceptions before calling NewObject

JNI functions while an exception is pending is not allowed.

Bug: 26763262
Change-Id: I679961961a0063f8657558cc4f0728571db336fd
a04b5c3d39232c7616591883ee2124520e3ab622 06-Mar-2015 Elliott Hughes <enh@google.com> Explicitly specify the icu:: namespace.

Bug: 15350832
Change-Id: I8d84f3e50b643806ccf01190797c69ce6445b539
b3aacde3d8af759ee4a7b395c636ea360547d92d 05-Nov-2014 Ian Rogers <irogers@google.com> Move from UniquePtr to std::unique_ptr.

Switch from stlport to libcxx as stlport lacks std::unique_ptr.

Change-Id: I45a3588a8ecf4689521f1df6654ed279a6d0669e
4e4b93ffe988b0a597835d852489573b57e0f3fe 30-Jul-2014 Narayan Kamath <narayan@google.com> Don't account buffer.arrayOffset() twice.

data[OUTPUT_OFFSET] from the perspective of native
code must always be the offset from the start of the
buffer passed in to it.

Change-Id: I4a5c9595aebd105c57ce2239dc95cf85d5bd6256
41c3d56dfdc92bd5710bdaf901f45d6c4da8fd0d 30-Jul-2014 Narayan Kamath <narayan@google.com> Don't account buffer.arrayOffset() twice.

data[OUTPUT_OFFSET] from the perspective of native
code must always be the offset from the start of the
buffer passed in to it.

bug: 16449607

(cherry picked from commit 4e4b93ffe988b0a597835d852489573b57e0f3fe)

Change-Id: Iddd3a835b72ae122c10e802bad92baffd0a85283
bd024cc687470a008999d96fd3af4a1261413d55 26-Nov-2013 Narayan Kamath <narayan@google.com> Fix several decoder bugs.

- NativeConverter should report unterminated character
sequences to managed code.
- CharsetDecoderIcu should report those errors correctly
from flush()
- InputStreamReader should check the return value of
flush() and not ignore it altogether.

bug: 11665359
bug: 10729779

Change-Id: Ic678a645a4ef2b3fe70e2c900c0cd393679f1037
f15b280ac1c2e32f7becdb314440c2999dc8d204 26-Nov-2013 Narayan Kamath <narayan@google.com> Fix an ASCIICharsetEncoderTest testcase.

Deal with truncated char sequences correctly.

bug: 10729779
Change-Id: I232b0ec899084270a6d621e6c7292ef8b94f8f7d
aaf01db628576a4e8c76c23b94d12adeefb7bbae 26-Aug-2013 Elliott Hughes <enh@google.com> Fix the Charset alias generation to use the correct icu4c API.

Bug: 10492721

(cherry picked from commit 783a57a7ece339bc246925e328bc82b50cae427a)

Change-Id: I53bbdf459944c6b5bcb134cae29c541bba17d2f8
783a57a7ece339bc246925e328bc82b50cae427a 26-Aug-2013 Elliott Hughes <enh@google.com> Fix the Charset alias generation to use the correct icu4c API.

Bug: 10492721
Change-Id: Ie81b8aca9d7531d0fd8476ccab78653b0aa68755
f5d8857b623192a985e449453de5bf1efaa4ea79 16-Aug-2013 Elliott Hughes <enh@google.com> Fix a bunch of Charset tests.

The isRegistered test is still failing. The problem is that icu4c's
convrtrs.txt has names like "windows-1252" that are both the canonical
name for one charset and an alias for another legacy charset. I need
to work out how to resolve that.

Bug: 10210999

(cherry picked from commit ea1caf4ccc5c2255f384c0774aa9e055763a6a41)

Change-Id: I83cf1b9ae1d29f9956f443ef914a3e473e0f4692
ea1caf4ccc5c2255f384c0774aa9e055763a6a41 16-Aug-2013 Elliott Hughes <enh@google.com> Fix a bunch of Charset tests.

The isRegistered test is still failing. The problem is that icu4c's
convrtrs.txt has names like "windows-1252" that are both the canonical
name for one charset and an alias for another legacy charset. I need
to work out how to resolve that.

Bug: 10210999
Change-Id: If3425321c814622e4f54b2efca95a767bd16c080
5ec6bf8d033754e06a463adb091d2c0afd0755ac 08-Aug-2013 Elliott Hughes <enh@google.com> Fix various Charset tests, clean up the implementation.

Bug: 10211558
Bug: 10211378
Change-Id: Ib3f97430f62163c0459c53e0c282ae0ca840e0af
3aac4ddc4d17c07fa8b4908069d23d5401a77993 05-Feb-2013 Elliott Hughes <enh@google.com> Add icu4c-backed transliteration.

Change-Id: I4194810646a2a0661331aaf941fb5f99ce7758b1
6c1e5f4ad36c1f51687aa2b059e998a7c2db2e36 26-Jan-2013 Elliott Hughes <enh@google.com> Manually update the libcore native code.

Cherry-picking all the individual tiny cleanups from the internal branch was
too hard.

Change-Id: Ib97643d3502295685390854c9edd97c93c4c2ecf
5ec69b20ab9b3e2dcbe225d548168b09afbbbac2 24-Jul-2012 Elliott Hughes <enh@google.com> Clean up ICU error reporting.

Throw all ICU exceptions from the native side, and include the name of the
function that failed.

Bug: 5037042
Change-Id: I49b5493a7e7365226d612479294b5b8f47ec4e8c
7cd6760f7045d771faae8080a8c6150bf678f679 04-May-2012 Elliott Hughes <enh@google.com> Make libjavacore independent of libnativehelper for the PDK.

Bug: 6369821
Change-Id: Ie038571a5dac1f301c0c3c6fb84df432e67b62c0
bef9ec33e1368f57c731fce63b6a8c61628c64b0 19-Apr-2011 Elliott Hughes <enh@google.com> Clean up ICU exception throwing.

Change-Id: Ifce086e1fb20b7cb99673f4d38c8c56144328295
57d0a10f4fa6cae6d5c63b4f799e048e83c5d11e 03-Mar-2011 Elliott Hughes <enh@google.com> Make all filenames match their classes.

Change-Id: I2c9f95a27ee3881fc609e3e4f1468205c701215d