Skip to content

Fix/jni modified utf8 decoding - #10

Closed
CHISANW wants to merge 2 commits into
iscc:developfrom
CHISANW:fix/jni-modified-utf8-decoding
Closed

CHISANW wants to merge 2 commits into
iscc:developfrom
CHISANW:fix/jni-modified-utf8-decoding

Conversation

@CHISANW

@CHISANW CHISANW commented Oct 8, 2026

Copy link
Copy Markdown

Summary

Fix incorrect decoding of Java strings containing Unicode characters outside the BMP (e.g., emoji).

Changes

  • Replace to_string_lossy() with String::from() to correctly decode JNI modified UTF-8.
  • Prevent Unicode characters from being replaced with U+FFFD.
  • Fix text extraction and metadata decoding.

Testing

  • Existing tests do not cover non-BMP Unicode characters.
  • Regression test not yet added.

titusz and others added 2 commits July 23, 2026 21:57
`GetStringUTFChars` returns modified UTF-8, which encodes characters
outside the BMP as a CESU-8 surrogate pair. Decoding that buffer as
plain UTF-8 replaced every such character with U+FFFD, so emoji and
CJK extension ideographs were lost from extracted text and metadata.
titusz added a commit that referenced this pull request Oct 9, 2026
…uncation (#11)

- Read Java strings as UTF-16 code units, so characters outside the Basic
  Multilingual Plane survive extraction (previously each became six U+FFFD)
  and an unpaired surrogate becomes a single U+FFFD.
- Look up metadata values with the original Java key, so keys holding an
  unpaired surrogate keep their values.
- Raise the default extract_string_max_length from 500,000 to 10,000,000;
  any negative value disables the limit.
- Flag text cut off at the limit with Tika's
  X-TIKA:EXCEPTION:write_limit_reached metadata key (exported as
  WRITE_LIMIT_REACHED) and drop a dangling high surrogate at the cut.
- Add Rust and Python regression tests, run the Rust test suite in CI, run
  CI on pull requests to develop, and keep test fixtures out of the file
  hygiene hooks.

Supersedes #10.

Co-authored-by: CHISANW <keuye06380618@gmail.com>
@titusz

titusz commented Oct 9, 2026

Copy link
Copy Markdown
Member

Thank you @CHISANW for finding this and for the fix! Your change was the starting point for #11, which is now merged into develop with you credited as co-author (5745c54).

#11 builds on your modified UTF-8 approach and goes one step further: Java strings are now read as UTF-16 code units, so an unpaired surrogate (for example from text cut at the length limit) costs a single U+FFFD instead of garbling the whole string. It also adds regression tests for Rust and Python. The fix will ship in the next release. Closing this PR in favor of #11.

@titusz titusz closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants