You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
kotlin-sdk: JNI string arguments are decoded lossily, so malformed UTF-16 is rewritten instead of rejected #6154
rs-unified-sdk-jni reads Kotlin String arguments with env.get_string(s).into(). In the pinned jni 0.21.1, that conversion decodes Java's modified UTF-8 and, when decoding fails, falls back to String::from_utf8_lossy. A string containing an unpaired UTF-16 surrogate therefore reaches Rust as different text, with U+FFFD in place of the surrogate, and the call goes ahead with it.
For a paid memo (shieldedShieldToRecipient, shieldedShieldFromIdentityToRecipient) or a token public note, the recipient can receive text the caller never supplied, as long as the rewritten text still fits the length limit.
A few helpers also treat an unreadable string as absent instead of failing:
tokens.rs and wallet_manager.rsread_cstring_opt drop a note, memo, label, user agent or devnet name;
queries.rsopt_c_string drops a query filter or cursor, so the query runs without it;
sdk.rsto_c_string drops a DAPI address list or quorum URL, so the default is used;
the vote path drops contenderIdentityId.
Fix direction
One strict helper in support.rs that every string argument goes through. It copies the UTF-16 code units and decodes them with String::from_utf16, so an unpaired surrogate is an error and supplementary characters still cross intact, independent of how the VM encodes modified UTF-8. Call sites throw DashSDKException (code 1) on a malformed or unreadable string instead of substituting or dropping it.
Tests
Rust unit tests for the decoder: well-formed text including a supplementary character and an embedded NUL; lone high, lone low, trailing high and reversed surrogates rejected.
Instrumented binding test: a memo with an unpaired surrogate is refused at the JNI boundary; a 32-byte memo of supplementary characters reaches the FFI.
Context
Raised by the automated review on #5896 (read_cstring_opt in funding.rs, used for the recipient memo). The same conversion is used in 13 files of the JNI crate, so it is fixed in one place rather than in that PR. Swift is not affected: it passes UTF-8 C strings.
Activity
fix(kotlin-sdk): reject malformed UTF-16 string arguments at the JNI …
fix(kotlin-sdk): reject malformed UTF-16 string arguments at the JNI …
fix(kotlin-sdk): reject malformed UTF-16 string arguments at the JNI …
fix(kotlin-sdk): reject malformed UTF-16 string arguments at the JNI …