wclayer: fix sparse file logical size #2926
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.39) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 256 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.332
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2926"
general
weight: 0.35
jterry75
Summary
Prevent Windows container layer export from writing an all-hole sparse file as a zero-byte tar entry, which truncates the file's contents on export.
A sparse file can have a nonzero logical size without allocated data—for example, a 1 MiB file containing only zeroes. In this case the first
BackupDatastream reports size zero even though the file's logical EOF is 1 MiB.findBackupStreamSizepreviously used thatBackupDatasize directly. The resulting zero size was passed to the tar writer, so the exported entry was treated as empty and the file was restored truncated.Keep the existing fast path for non-sparse files and sparse files with inline data. For a sparse
BackupDatastream with no inline data, derive the logical size fromBackupSparseBlockrecords instead: the terminal zero-length block'soffset marks logical EOF, and allocated blocks satisfy
offset+size <= logical size, so the maximum end position is the logical size.Add regression coverage for regular files and sparse files with empty, all-hole, single-range, and multi-range layouts.
Context
Reported downstream in Docker/Moby as moby/moby#53464: building or committing a Windows image whose layer contains an NTFS sparse file fails.
That failure has two independent causes in two libraries:
0, truncating its contents on export.BackupSparseBlockrecords withunknown stream ID 9.The two fixes are complementary. This change touches only
findBackupStreamSizeand uses existing go-winio APIs, so it builds, tests, and merges independently of go-winio#375. Once that PR lands and is tagged, a follow-up will bump the go-winio dependency here so a tagged hcsshim release carries the complete end-to-end fix.Testing
go test ./internal/wclayer