← Back to Pull requests

Security: fail open of corrupt-SST artifacts with an error, not os.Exit(1) #1161

Closed
unknown closed this pull request without merging on Oct 03, 2026 19:29 UTC
View on GitHub
unknown unknown commented on Oct 03, 2026 15:15 UTC
Author

Summary

C1Z-SEC-005: a v3 .c1z whose Pebble checkpoint has one flipped byte inside an SST data block killed the process that opened it. The file sizes stay equal to what the MANIFEST records, so pebble.Open's size check passes. The first read of the block then went through pebble's default DataCorruption handler, which calls Logger.Fatalf, and our logger's Fatalf called os.Exit(1). Any process that opened an untrusted artifact died: the shared compaction worker, syncer previous-sync opens, the CLI.

Changes

  • Corruption is an error. newPebbleOptions always installs EventListener.DataCorruption. The read that hits the block returns pebble's corruption error; pebble.IsCorruptionError still holds after the store layer wraps it. The event is logged at ERROR via zap.L() with the file path, key bounds and details. There is no option to turn this off.

  • A corrupt keyspace is never checkpointed. The engine records the first corruption event. CheckpointTo then refuses and wraps the original corruption error. This matters for background compactions, whose error reaches no caller: without the refusal, a writable store could save the corrupt table into a new artifact. CheckpointTo is the only path to a saved artifact (store save, clone-sync), and a refused save comes back out of Close as ErrArtifactUnusable. The listener records into an Engine allocated before rawdb.Open, so nothing is written to shared state after pebble's goroutines start.

  • Logging and Fatalf. discardPebbleLogger.Errorf and Fatalf log through zap.L() instead of writing to stderr; pebble.Logger carries no ctx. Fatalf panics instead of calling os.Exit(1). Its remaining callers are pebble's internal invariant checks and failed MANIFEST or WAL writes. The panic carries a stack trace, and a caller that recovers it must stop using the engine.
  • WALs are not a second route to the old Fatalf. Saved payloads carry empty WALs (CheckpointTo truncates them; TestCheckpointWALsAreEmpty), and a corrupt WAL fails pebble.Open's replay with an error.

    Compatibility

  • No exported API change.

  • pkg/dotc1z/engine/pebble consumers get a corruption error where the process used to exit.

  • zap.L() is a no-op unless the program installs a global logger. pkg/logging installs one; before this change these lines always went to stderr.
  • Tests

  • TestSecurity_CorruptSSTFailsWithError (pkg/dotc1z):

  • - Setup: write an honest c1z, unpack it, flip a mid-file byte of the largest SST, and re-frame it.
    - It opens the result writable and read-only, lists resources, and asserts pebble.IsCorruptionError. The read-only case also covers the store's writable migration pre-open.
    - With the listener removed, the test panics with pebble FATAL: on-disk corruption ... crc32c checksum mismatch.
  • TestCheckpointToRefusesAfterCompactionFindsCorruption (pkg/dotc1z/engine/pebble):

  • - Setup: a corrupt table plus an overlapping L0 table, so CompactAllRanges reads the corrupt block.
    - CheckpointTo then fails with a corruption error.
    - With the guard removed, CheckpointTo succeeds and the test fails.
  • golangci-lint run ./...: 0 issues.

  • go test -short -tags=baton_lambda_support ./... passes.

  • go test -race passes on pkg/dotc1z/engine/pebble and on TestSecurity_CorruptSSTFailsWithError.
  • Diff: 421 lines (+315 / -106) across 5 files Reviewer: pquerna Review duration: 254m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.68) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.68 · 421 lines diff across 5 files
    0.68
    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%
    57%
    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.362
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.068
    Real PR Conversation Timeline
    1 comments
    "Review active on #1161"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 58.0% reviewed sensitive_module
    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: 68.2% (HIGH) · Higher = larger blast radius
    68.2%
    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: 58.0% · Lower = rushed or shallow review
    58.0%
    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: 28.6% · Safe to merge
    28.6%