janestreet / janestreet/procfs
Reusable file reader can retain stale bytes after a read exception
- Dominant language
- OCaml
- Stars
- 1
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
`input_all_with_reused_buffer` deliberately keeps a `Buffer.t` across calls to reduce allocation pressure in `get_all_procs`. The buffer is currently cleared only after a complete successful read.
If `Unix.read` raises after one or more chunks were appended, the exception leaves those bytes in the reusable buffer. The next `Blocking_IO.string_of_file` call starts appending to the same buffer and can return stale bytes from the failed file prefixed to unrelated `/proc` contents. A transient read error can therefore poison later reads in the same process.
The buffer should be empty at the start of each read and cleared in a `finally` block on both success and failure. I have a focused patch ready that makes that lifecycle explicit without changing the reuse optimization.
Contributor guide
Research direction
Start at input_all_with_reused_buffer and follow its use from get_all_procs through Blocking_IO.string_of_file. Inspect the reusable Buffer.t lifecycle around successful and exceptional Unix.read calls. Done means a failed read cannot affect the next file read while the existing buffer-reuse behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100