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

UnsafeByteArrayInputStream.read for bytes >= 0x80 returns negative integer, caller thinks "Oh, EOF" #87

Closed
neopaf opened this issue Mar 13, 2020 · 1 comment

Comments

@neopaf
Copy link

neopaf commented Mar 13, 2020

Michel, first let me thank you enourmously for your efforts.
I'm basing my custom binary format on your approach and that saved me tons of investigations.

I've found/fixed small bug you may want to fix back in your code:

before

    @Override
    public int read() {
        return _pos >= _count ? -1 : _buf[_pos++];
    }

Here, when buffer contains byte with sign bit on this code returns negative integer.

CountingInputStream.read caller assumes EOF situation, while there are more bytes available.

Premature EOF causes stops further parsing of input buffer past 0x80 (or higher) byte.

suggest this

    @Override
    public int read() {
        return _pos >= _count ? -1 : (_buf[_pos++] & 0xFF); // PAF bugfix
    }
@neopaf neopaf changed the title UnsafeByteArrayInputStream.read for bytes >= 0x80 does not advance pos UnsafeByteArrayInputStream.read for bytes >= 0x80 returns negative integer, caller thinks "Oh, EOF" Mar 13, 2020
@michel-kraemer
Copy link
Owner

michel-kraemer commented Mar 21, 2020

Thanks. This looks really interesting. Can you provide sample data that causes the issue? If possible, can you also write a unit test that demonstrates the problem so that we can cover against regressions in the future? Thanks.

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