Description
I tried this code:
std::fs::read("my-file")
for a file that is <1MB large.
I expected to see this happen: The read should allocate a vec that is as large as the file content. The heap size in Emscripten should not meaningfully change.
Instead, this happened: The Emscripten heap grows by 1.8GB
I looked into the implementation of fs::read. Since it uses the file metadata size to pre-allocate the output vector, I debug printed the file size, which is around 1.8GB.
Since my Rust code is running inside Pyodide 0.25, I also checked Python's os.stat of the file, which reports the correct file size. Reading the file in Python also succeeds without the enormous over-allocation. It seems that this is a Rust-specific bug in getting the correct file size information from Emscripten.
Meta
My Rust toolchain is pinned to nightly-2024-07-21, the last nightly for 1.81.