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
Prevent seek_in
from marking buffer data as valid after closing the channel (Fixes #11878)
#11965
Conversation
The test you introduced fails on Windows. Maybe |
Better use |
Add a test demonstrating issue ocaml#11878
If offset keeps its value when the channel is closed, it is possible to `seek_in` backward which will only decrease `channel->curr` and therefore mark some buffer bytes as valid: further calls to `input_byte` would succeed on the closed channel Fix issue ocaml#11878
Thank you for the tip! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The change makes complete sense and there's a test.
I'm trying to understand this weird Naive question: why don't we fix the present issue by failing on This requires changing the test introduced in the present PR, let ic = open_in_bin Sys.argv.(0) in
seek_in ic nb_bytes;
close_in ic;
seek_in ic 0;
assert (
try
ignore (input_byte ic);
false
with
| Sys_error _ -> true
| _ -> false) to move the |
This reverts a technical decision made in ocaml#11878, ocaml#11965, for the purpose of simplifying the implementation of [close_in] and the specification of [seek_in], which now consistently fails on closed channels.
… channel (ocaml#11965) * Test calls to input_byte after close_in Add a test demonstrating issue ocaml#11878 * Reset offset when closing a channel If offset keeps its value when the channel is closed, it is possible to `seek_in` backward which will only decrease `channel->curr` and therefore mark some buffer bytes as valid: further calls to `input_byte` would succeed on the closed channel Fixes: ocaml#11878 (cherry picked from commit a606e92)
This proposes a fix for issue #11878 in which some part of a
in_channel
buffer can be considered as valid after the channel has been closed.This works by simply resetting the channel offset to 0 when the channel is closed to disable any backward
seek_in
later.This PR also introduces a test for that issue (before and with the fix).
Closes issue #11878