-
Notifications
You must be signed in to change notification settings - Fork 39
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
take_seek doesn't correctly limit std::io::SeekFrom::End
#291
Labels
Comments
csnover
added a commit
to csnover/binrw
that referenced
this issue
Oct 13, 2024
ismell
added a commit
to ismell/binrw
that referenced
this issue
Oct 14, 2024
This change adds support for the missing SeekFrom operations. It refactors the internals a bit. We now keep a range of start..end values that are accessible to the TakeSeek. I dropped manually computed stream position and instead call the inner's `stream_position()`. This does mean that `limit` needs to take in a `&mut`. I was also going to change the return type to `Result<u64>`, but that would force all callers to handle the `Result`, which I felt like it was a bigger API change. I fixed the test added in 38b3598 because `StartFrom::Start(0)` used to reset the cursor to the start of the underlying buffer. Fixes jam1garner#291.
csnover
added a commit
to csnover/binrw
that referenced
this issue
Nov 27, 2024
The purpose of `TakeSeek` is to be a binrw-compatible version of `std::io::Take`, and the purpose of `std::io::Take` is only to truncate the stream to a certain number of bytes, not to extend the stream if a limit beyond the length of the inner stream is given. Thus, `TakeSeek` also needs to pay attention to the true end of the inner stream and use that as the `SeekFrom::End(0)` position if it is less than the limit. Refs jam1garner#291.
csnover
added a commit
to csnover/binrw
that referenced
this issue
Dec 1, 2024
The purpose of `TakeSeek` is to be a binrw-compatible version of `std::io::Take`, and the purpose of `std::io::Take` is only to truncate the stream to a certain number of bytes, not to extend the stream if a limit beyond the length of the inner stream is given. Thus, `TakeSeek` also needs to pay attention to the true end of the inner stream and use that as the `SeekFrom::End(0)` position if it is less than the limit. Refs jam1garner#291.
csnover
added a commit
to csnover/binrw
that referenced
this issue
Dec 1, 2024
The purpose of `TakeSeek` is to be a binrw-compatible version of `std::io::Take`, and the purpose of `std::io::Take` is only to truncate the stream to a certain number of bytes, not to extend the stream if a limit beyond the length of the inner stream is given. Thus, `TakeSeek` also needs to pay attention to the true end of the inner stream and use that as the `SeekFrom::End(0)` position if it is less than the limit. Refs jam1garner#291.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that take_seek doesn't actually remap anything when calling
seek
. That means that callingseek
can put the pointer outside of the defined buffer.The following assert fails because the
seek
operation doesn't take into account the start and end constraints.The text was updated successfully, but these errors were encountered: