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

Limit reading CharBuffer.array() to CharBuffer.limit() to avoid additional NULL characters at the end of some inputs #1452

Merged
merged 3 commits into from
Dec 10, 2020

Conversation

hannibal218bc
Copy link
Contributor

It is not documented explicitly, but CharBuffer.array() "Returns the char array that backs this buffer", so the buffer may have excess space at the end that was not used for the input.

(See also the explanation why https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6442955 is not a bug:

The Charset Buffer API is optimized for efficiency, not convenience. Buffer copies are avoided, but this means some buffers have extra elements between their limit and their capacity.

)

In a recent change to DataUtil the array() was passed without restricting its use to the length of limit(), hence adding NULL characters at the end.

Fixed by passing the value of limit() to the CharArrayReader that is actually reading from the array().

to avoid additional NULL characters at the end of some inputs
@hannibal218bc hannibal218bc changed the title Limit CharBuffer.array() to CharBuffer.limit() to avoid additional NULL characters at the end of some inputs Limit reading CharBuffer.array() to CharBuffer.limit() to avoid additional NULL characters at the end of some inputs Nov 16, 2020
@jhy jhy merged commit 22405b7 into jhy:master Dec 10, 2020
@jhy
Copy link
Owner

jhy commented Dec 10, 2020

Thanks! Merged.

@jhy jhy added this to the 1.14.1 milestone Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants