← Back to Pull requests

Fix zstd decompression buffer corruption #4278

Closed
unknown closed this pull request without merging on Sep 14, 2026 11:01 UTC
View on GitHub
unknown unknown commented on Sep 09, 2026 21:16 UTC
Author

Fixes data corruption issue when trying to import a zst image.
Essentially the issue boils down to how cdi finds out which compressed
format the data is inside matchHeaders.

1) matchHeader reads 512 bytes from the raw network reader into fr.buf
2) It detects zst and pushes a zst reader to the reader stack
3) matchHeader uses the zst reader to read the first zstd block which
in the case of my image was only 100b long. It then saves the decompressed data of 512 bytes back into fr.buf but we only read part of the original fr.buf.
This causes us to overwrite compressed data with decompressed data.
4) The next read from the zst reader then tries reading decompressed
data as a zst header and sees a very high window size leading to the
error failed to pull image: window size exceeded

This issue can also technically arrive with xz since it has block headers that can get clobbered, but gz cannot since it uses fixed size windows.

What this PR does / why we need it:

  • Clone header buffer (bytes.Clone) when wrapping with bytes.NewReader in matchHeader to prevent subsequent format detection passes from overwriting unconsumed compressed bytes.

  • Add rdrZstd constant and mapping to rdrTypM.

  • Add test coverage for .iso.zst reader construction and streaming decompression.
  • This PR is needed to fix a data corruption crash in the importer pod experienced when trying to import a variable window size compressed image

    Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
    Fixes #4277

    Special notes for your reviewer:

    Release note:
    <!-- Write your release note:
    1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
    2. If no release note is required, just write "NONE".
    -->
    ``release-note
    NONE
    ``

    Diff: 250 lines (+187 / -63) across 3 files Reviewer: akalenyu Review duration: 6584m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 250 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%
    60%
    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.331
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4278"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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.0% (MEDIUM) · Higher = larger blast radius
    39.0%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.4% · Safe to merge
    15.4%