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

ArrayIndexOutOfBoundsException on input with multiple bytes for a character #32

Closed
ktulinger opened this issue Jan 2, 2024 · 3 comments

Comments

@ktulinger
Copy link

ktulinger commented Jan 2, 2024

When using

Ulid.from(String)

it fails with

java.lang.ArrayIndexOutOfBoundsException: Index 3617 out of bounds for length 256
	at com.github.f4b6a3.ulid.Ulid.isValidCharArray(Ulid.java:801)
	at com.github.f4b6a3.ulid.Ulid.toCharArray(Ulid.java:776)
	at com.github.f4b6a3.ulid.Ulid.from(Ulid.java:325)

when the input string contains characters represented by more than 1 byte - in this example 3617. I had a string of length 26 java char however some of them are 2 bytes, rather than 1 (java char type is 2B). I'd expect the library to handle the input validity correctly and consistently throw IllegalArgumentException on invalid input.

@fabiolimace
Copy link
Member

The validator did not expect multibyte characters.

I changed the validation method to catch ArrayIndexOutOfBoundsException and return false (invalid) so that IllegalArgumentException is thrown instead.

See this commit 733242f.

@fabiolimace
Copy link
Member

Released v5.2.3! 🎉

@ktulinger
Copy link
Author

Thank you for the quick turnaround. I believe checking the array boundaries instead of try-catch is preferred approach overall. But thanks anyway.

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

No branches or pull requests

2 participants