cmd: fix limitedRead returning nil error when Stat fails - #2905
Open
Nilesh Patil (nileshpatil6) wants to merge 1 commit into
Open
cmd: fix limitedRead returning nil error when Stat fails#2905Nilesh Patil (nileshpatil6) wants to merge 1 commit into
Nilesh Patil (nileshpatil6) wants to merge 1 commit into
Conversation
In containerd-shim-runhcs-v1, limitedRead checked the Stat result inside
an if statement, so the err in the final return referred to the outer err
from os.Open, which is always nil at that point. errors.Wrapf returns nil
for a nil error, so a Stat failure returned ([]byte{}, nil) and the delete
handler silently skipped the shim panic log without logging a warning.
Restructure the function the way the containerd-shim-lcow-v2 copy already
does, and switch both copies from f.Read to io.ReadFull with the read
count sliced off, so a short read cannot hand back NUL padding that was
never in the file. Add the same limitedRead unit tests the lcow shim has.
Signed-off-by: nileshpatil6 <technil6436@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
limitedReadincmd/containerd-shim-runhcs-v1/delete.gocan return a nil error on failure. TheStatresult is checked inside anifstatement, so itserris scoped to that statement, and theerrin the final return refers to the outer variable fromos.Open, which is always nil once execution gets there:errors.Wrapfreturns nil for a nil error, so aStatfailure produces([]byte{}, nil). The caller in the delete handler then takes neither branch:err == nil && len(logBytes) > 0is false, anderr != nilis false, so the shim panic log is silently skipped without even the "failed to open shim panic log" warning.Change
containerd-shim-lcow-v2copy (cmd/containerd-shim-lcow-v2/manager.go) already does, so theStaterror is actually returned.f.Read(buf)toio.ReadFullwith the read count sliced off.f.Readmay return fewer bytes than requested without an error, and the old code returned the full buffer regardless, so a short read handed back NUL padding that was never in the file. Same reasoning as ext4/dmverity: use io.ReadFull when reading the super block and root hash #2888.limitedReadunit tests the lcow shim already has, since the runhcs-v1 copy had none.Verification
on Windows 11.