forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent
seek_in
from marking buffer data as valid after closing the…
… 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)
- Loading branch information
1 parent
77f09d8
commit 5e2c51f
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(* TEST *) | ||
|
||
(* Test that inputting bytes from a closed in_channel triggers an exception *) | ||
|
||
(* The number of bytes we'll rewind after closing; a value | ||
between 1 and IO_BUFFER_SIZE *) | ||
let nb_bytes = 3 | ||
|
||
let () = | ||
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) |