You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IO.readFile produces a string that is not contained in the original file.
Context
This came up while trying to read /proc/{pid}/cmdline, which contains null bytes but is valid UTF8.
Steps to Reproduce
Run the following, adjusting path to be a temporary file of your choice
#evaldolet path := "/tmp/lean4-4891"
IO.FS.writeBinFile path
("Hello\x00(this is a very secret message that must never be shared) world".toUTF8)
let x ← IO.FS.readFile path
IO.println x
Expected behavior: The secret message is visible
Actual behavior: The output is Hello world. The first 64-byte chunk ends at the the ) character, and is discarded due to the null byte.
Versions
4.10.0
Additional Information
[Additional information, configuration or data that might be necessary to reproduce the issue]
This PR:
- changes the implementation of `readBinFile` and `readFile` to only
require two system calls (`stat` + `read`) instead of one `read` per
1024 byte chunk.
- fixes a bug where `Handle.getLine` would get tripped up by a NUL
character in the line and cut the string off. This is caused by the fact
that the original implementation uses `strlen` and `lean_mk_string`
which is the backer of `mk_string` does so as well.
- fixes a bug where `Handle.putStr` and thus by extension `writeFile`
would get tripped up by a NUL char in the line and cut the string off.
Cause here is the use of `fputs` when a NUL char is possible.
Closes: #4891Closes: #3546Closes: #3741
Prerequisites
Please put an X between the brackets as you perform the following steps:
https://github.com/leanprover/lean4/issues
Avoid dependencies to Mathlib or Batteries.
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
IO.readFile
produces a string that is not contained in the original file.Context
This came up while trying to read
/proc/{pid}/cmdline
, which contains null bytes but is valid UTF8.Steps to Reproduce
path
to be a temporary file of your choiceExpected behavior: The secret message is visible
Actual behavior: The output is
Hello world
. The first 64-byte chunk ends at the the)
character, and is discarded due to the null byte.Versions
4.10.0
Additional Information
[Additional information, configuration or data that might be necessary to reproduce the issue]
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: