Skip to content

fix: guard against nil chunk in bucket.Get to prevent panic on corrupted cache load#97

Open
cubic-dev-ai[bot] wants to merge 1 commit intomasterfrom
fix/nil-chunk-panic-on-get
Open

fix: guard against nil chunk in bucket.Get to prevent panic on corrupted cache load#97
cubic-dev-ai[bot] wants to merge 1 commit intomasterfrom
fix/nil-chunk-panic-on-get

Conversation

@cubic-dev-ai
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot commented Apr 15, 2026

Summary

  • Adds a nil check for the chunk in bucket.Get before any slice expressions are evaluated, preventing a runtime panic when corrupted persisted cache data points to an unallocated chunk slot
  • When a nil chunk is encountered, the corruption counter is incremented and the entry is treated as a cache miss (consistent with existing corruption handling)
  • Adds a test verifying that Get on a nil chunk returns a miss and increments the corruption counter instead of panicking

Context

When cache data is loaded from a corrupted file via LoadFromFile*, map entries (b.m) may reference chunk indices that fall within len(chunks) but point to nil slots (chunks beyond the saved chunksLen are never allocated). The existing guard checked chunkIdx >= uint64(len(chunks)) but did not verify the chunk itself was non-nil, allowing chunk[idx : idx+4] to panic.

Test plan

  • New test TestBucketGetNilChunkNoCorruptionPanic verifies nil chunk produces a miss with corruption counter incremented
  • All existing tests pass (go test -count=1 ./...)
  • go vet ./... clean

🤖 Generated with Claude Code


Summary by cubic

Prevent panic in bucket.Get when corrupted cache data points to a nil chunk. Nil chunks now return a miss and increment the corruption counter instead of crashing.

  • Bug Fixes
    • Added nil check for chunk before any slice ops in bucket.Get.
    • Treat nil chunk as miss and increment corruptions.
    • Added test TestBucketGetNilChunkNoCorruptionPanic to verify behavior.

Written for commit 97e7b90. Summary will update on new commits.

When cache data is loaded from a corrupted file, map entries may point
to chunk indices that are allocated but nil (beyond the saved chunksLen).
The existing bounds check verified chunkIdx against len(chunks) but did
not verify the chunk itself was non-nil before slicing it, which could
cause a runtime panic instead of being counted as a corruption miss.

Add a nil check for the chunk immediately after retrieval from the
chunks slice, before any slice expressions are evaluated.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.81%. Comparing base (cef9ae9) to head (97e7b90).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #97      +/-   ##
==========================================
+ Coverage   76.68%   76.81%   +0.12%     
==========================================
  Files           4        4              
  Lines         549      552       +3     
==========================================
+ Hits          421      424       +3     
  Misses         73       73              
  Partials       55       55              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Author

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants