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

reading from an incoming stream that may not fill an entire (expected) buffer in one go may cause corruption metadata #129

Open
85danf opened this issue Jan 17, 2018 · 0 comments

Comments

@85danf
Copy link

85danf commented Jan 17, 2018

The logic ReadableChannelWrapper::read expects to have the buffer filled in its entirety in one go since it will call consumers with the buffer flipped (so it reports the remaining counter as the total amount read).

Consider an incoming InputStream that is not file-system based (say, nfs or incoming from socket) and may not fill the entire buffer (which has an expected size) in one read:
Suppose buffer is allocated with 100 and first read call fills it with 30.

In the case we observed consumers are now called with buffer.duplicate().flip() which will report 30 as as its remaining().
we had a 'byte counting' consumer (inited with ReadableChannelWrapper::start) which simply has the logic count += buffer.remaining()

so count is now at 30.

Suppose next read gets another 20.
Now buffer.remaining() == 50 so count += buffer.remaining() --> 80 (instead of 50) and so on.

This will cause the byte counter to report numbers that are way off.

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

1 participant