Skip to content

Fix nocache short-read tail initialization#60

Open
XavLimSG wants to merge 1 commit intogoogle:mainfrom
XavLimSG:fix/nocache-short-read-zero-fill
Open

Fix nocache short-read tail initialization#60
XavLimSG wants to merge 1 commit intogoogle:mainfrom
XavLimSG:fix/nocache-short-read-zero-fill

Conversation

@XavLimSG
Copy link
Copy Markdown

@XavLimSG XavLimSG commented Apr 5, 2026

Fixes #59

Summary

In -o nocache mode, Read() can get a short read from Reader::Read when hitting sparse regions. The code shrinks dst to the unread tail and adds dst.size() to the return length, but the std::ranges::fill(dst, '\0') line that should zero-fill that tail is currently commented out. In release builds (no assert), this means uninitialized buffer contents get returned to the caller.

Changes

  • fuse-archive.cc: Uncomment std::ranges::fill(dst, '\0') so unread tail bytes are explicitly zeroed before the return length is inflated.
  • test/test.py: Add TestNocacheSparseReadIsZeroFilled regression test that generates a sparse tar archive, mounts with -o nocache,direct_io, reads the sparse region at multiple offsets/sizes, and asserts all returned bytes are NUL.

How to test

The new test covers the exact scenario. Run the existing test suite:

python3 test/test.py

In nocache mode, Read() can receive a short read from Reader::Read for sparse regions. The unread tail must be zero-filled before we inflate the returned length.

This change restores std::ranges::fill(dst, '\0') and adds a regression test that mounts a generated sparse archive with -o nocache,direct_io, reads hole regions, and asserts all returned bytes are NUL.
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 5, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uninitialized heap data returned in nocache mode when Reader::Read produces short read

1 participant