← Back to Pull requests

wclayer: fix sparse file logical size #2926

Closed
unknown closed this pull request without merging on Sep 17, 2026 20:50 UTC
View on GitHub
unknown unknown commented on Sep 11, 2026 23:30 UTC
Author

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 BackupData stream reports size zero even though the file's logical EOF is 1 MiB.

findBackupStreamSize previously used that BackupData size 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 BackupData stream with no inline data, derive the logical size from BackupSparseBlock records instead: the terminal zero-length block's
offset 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:

  • This PR (hcsshim): the logical size of an all-hole sparse file is computed as 0, truncating its contents on export.

  • go-winio (microsoft/go-winio#375): the seekable export path rejects BackupSparseBlock records with unknown stream ID 9.
  • The two fixes are complementary. This change touches only findBackupStreamSize and 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
  • Diff: 256 lines (+192 / -64) across 3 files Reviewer: jterry75 Review duration: 8480m
    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
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.1% (MEDIUM) · Higher = larger blast radius
    39.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.9% · Safe to merge
    16.9%