-
Notifications
You must be signed in to change notification settings - Fork 24
Uninitialized heap data returned in nocache mode when Reader::Read produces short read #59
Description
Hi maintainers,
I found a correctness issue in the Read() path for -o nocache mode.
When Reader::Read(offset, dst) returns short (for example during sparse-hole reads), the code shrinks dst to the unread tail and then adds dst.size() to the return length. But the NUL padding line is currently commented out, so the unread tail bytes are never initialized before being counted as returned data.
Relevant code (fuse-archive.cc, around line 3398):
ssize_t n = r->Read(offset, dst);
assert(n >= 0);
assert(n <= dst.size());
dst = dst.subspan(n);
// std::ranges::fill(dst, '\0'); // <-- disabled
assert(std::ranges::all_of(dst, [](char const c) { return c == '\0'; }));
n += dst.size();
return static_cast<int>(n);In release builds (where assert is compiled out), this means the buffer tail goes back to the caller with whatever happened to be in heap memory.
The fix is straightforward: uncomment the std::ranges::fill(dst, '\0') line so that unread tail bytes are explicitly zeroed before inflating the return length.
I have a patch and a regression test ready. Happy to open a PR if that works for you.