fix(utils): incorrect buffer length check in slice reader impl#383
fix(utils): incorrect buffer length check in slice reader impl#383irakliyk merged 1 commit intofacebook:mainfrom
Conversation
4cf85b9 to
9ae2b3d
Compare
|
@irakliyk I think it might be problematic to run |
irakliyk
left a comment
There was a problem hiding this comment.
Looks good! Thank you! Should we also add a test to prevent potential future regressions?
@irakliyk I think it might be problematic to run
clippy's nightly version when the MSRV of these crates is much lower, at least as a required check. At least in this case, it causes CI to fail even though I haven't made any changes to the affected code.
No worries - I can merge as is and then fix the lints in a follow-up commit.
Certainly!
This is actually the problem - I would have done that myself, but the issue is that the I'm not sure there is any great options, but figured I would mention it since the CI run failed in this case. |
When determining whether we have sufficient bytes available to read a slice, we were incorrectly looking at the total length of the current buffer, not the portion of the buffer that is unread. As a result, we wouldn't attempt to fill the buffer with more bytes, and a subsequent attempt to read the requisite bytes from the buffer would fail, because there weren't in fact enough to fufill the request from the unread portion of the buffer.
9ae2b3d to
345e5c2
Compare
|
@irakliyk I've added a test that reproduced the original issue without the patch, which now passes with this patch. The issue is a bit more subtle than I originally described, in that it only affects cases where we are reading from something that doesn't implement Should be good to go now! |
When looking into a deserialization issue in another project, I discovered that we were incorrectly checking the length of the unread buffer when attempting to read
Nbytes as a slice. As a result, deserialization would fail any timeread_slicewas called when the current total buffer length as>= N, but the unread portion was< N.