Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanner.scan utf8ByteIndexesMapping Array Out Of Bounds #170

Open
crusse54 opened this issue Dec 17, 2021 · 4 comments
Open

Scanner.scan utf8ByteIndexesMapping Array Out Of Bounds #170

crusse54 opened this issue Dec 17, 2021 · 4 comments
Labels

Comments

@crusse54
Copy link

image

final byte[] utf8bytes = input.getBytes(StandardCharsets.UTF_8) encodes the unknown character as a single byte ASCII question mark. When Util.utf8ByteIndexesMapping(input, bytesLength); creates the byteIndexes array of size bytesLength (the size of utf8bytes), it creates an array that is 2 smaller than it should be since the unknown character is 3 bytes. The set of if statements then references the original string and decide that the unknown character is 3 bytes, filling 3 array spots with the character index. Eventually Array.fill goes out of bounds and an exception is thrown.

image(1)

@gliwka
Copy link
Owner

gliwka commented Nov 20, 2023

Interesting, invalid UTF-8 characters are not handled properly and are replaced with an ASCII "?" instead of with U+FFFD. I will look into a different API that handles that correctly or a lower-level API that give me more control on how invalid chars are processed.

@gliwka
Copy link
Owner

gliwka commented Nov 20, 2023

Alternatively, I might also find a way to directly operate on the strings without the mapping. Let me know if you also have any ideas.

@gliwka gliwka added the bug label Dec 2, 2023
@yenuka78
Copy link

We also encountered this bug. When is a fix expected?

@gliwka
Copy link
Owner

gliwka commented Jan 26, 2024

Fix will be released in the upcoming days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants