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
Open
fix: guard against nil chunk in bucket.Get to prevent panic on corrupted cache load#97cubic-dev-ai[bot] wants to merge 1 commit intomasterfrom
cubic-dev-ai[bot] wants to merge 1 commit intomasterfrom
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bucket.Getbefore any slice expressions are evaluated, preventing a runtime panic when corrupted persisted cache data points to an unallocated chunk slotGeton a nil chunk returns a miss and increments the corruption counter instead of panickingContext
When cache data is loaded from a corrupted file via
LoadFromFile*, map entries (b.m) may reference chunk indices that fall withinlen(chunks)but point to nil slots (chunks beyond the savedchunksLenare never allocated). The existing guard checkedchunkIdx >= uint64(len(chunks))but did not verify the chunk itself was non-nil, allowingchunk[idx : idx+4]to panic.Test plan
TestBucketGetNilChunkNoCorruptionPanicverifies nil chunk produces a miss with corruption counter incrementedgo test -count=1 ./...)go vet ./...clean🤖 Generated with Claude Code
Summary by cubic
Prevent panic in
bucket.Getwhen corrupted cache data points to a nil chunk. Nil chunks now return a miss and increment the corruption counter instead of crashing.chunkbefore any slice ops inbucket.Get.corruptions.TestBucketGetNilChunkNoCorruptionPanicto verify behavior.Written for commit 97e7b90. Summary will update on new commits.