← Back to Pull requests

fix(disk): handle QCOW2 zero-cluster, OFLAG_COPIED, and short EOF tail in flatten #3081

Closed
unknown closed this pull request without merging on Nov 30, 2026 05:59 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 10:19 UTC
Author

TL;DR

Fixes QCOW2 flatten() correctness bugs in LiteBox::export: discarded zero-clusters no longer resurrect backing data, allocated L1/L2 entries set QCOW2_OFLAG_COPIED, short EOF clusters zero-pad instead of failing, and unsupported extended_l2 layers or mixed cluster_size backing chains are rejected before creating the output image.

Design doc: None (standalone bugfix).

Documentation: [docs/contributing/architecture/README.md](docs/contributing/architecture/README.md#per-box-lifecycle-ownership)

How it works

  • FlattenLayer::open parses QCOW2 v3 incompatible_features (hdr[72..80]) and rejects layers with QCOW2_INCOMPAT_EXTL2 (1 << 4), preventing 16-byte extended L2 subcluster bitmaps from being misread at 8-byte stride.

  • open_flatten_chain verifies every FlattenLayer::Qcow2 layer matches the top layer's cluster_bits before creating the output file (FlattenLayer::Raw layers are unaffected).

  • When an L2 entry sets bit 0 (0x1), read_cluster() returns zeros before data_offset == 0 fallback. Output L1/L2 entries OR 1 << 63 to match refcount = 1. Partial EOF reads (0 < n < 64 KiB) zero-pad the tail; n == 0 still errors.
  • Verification

  • BOXLITE_DEPS_STUB=1 make test:unit:rust FILTER=qcow2: 26/26 passed (including Defect Proof before/after for test_flatten_rejects_extended_l2_backing and test_flatten_rejects_mixed_cluster_sizes, plus qemu-img check).

  • make fmt:check:rust & make lint:rust: passed.

  • Pre-push make test (changed Rust unit + VM integration matrix): 308/308 VM integration tests passed.

  • Gaps: preallocated zero-clusters (offset != 0) and mid-chain zero-clusters.
  • Diff: 208 lines (+156 / -52) across 2 files Reviewer: DefeatMan Review duration: 6940m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 208 lines diff across 2 files
    0.36
    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.320
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3081"
    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: 36.4% (MEDIUM) · Higher = larger blast radius
    36.4%
    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: 14.4% · Safe to merge
    14.4%