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

Add defensive checks for NUL bytes in input strings #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

romseygeek
Copy link

If an input string contains a NUL byte, then the JNI string->char* conversion will get confused, and libpostal hangs in the native method call. This PR adds defensive checks to AddressParser and AddressExpander to prevent this.

@albarrentine
Copy link
Contributor

Thanks for the PR but this is actually a slightly more general problem. Wasn't aware of this, but apparently JNI uses a "modified UTF-8" (b/c Java needs to reinvent all of the wheels...), instead of standard UTF-8, which is required by libpostal. In addition to the NUL-byte terminator, it converts 4-byte UTF-8 sequences into two 3-byte surrogate pairs, which I'm not sure if utf8proc, our decoder, would handle correctly.

So I think I'd prefer to convert the strings to real UTF-8 byte arrays and just NUL-terminate them at the C/JNI level.

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