Repository navigation
Conversation
…ithout references Store.DeleteReference allocated its new slice with capacity len(mapping.References)-1, which is -1 (makeslice: cap out of range) when the owner mapping has no references yet. Use len(mapping.References).
ch33hau
requested review from
a team,
FabianKramm,
janekbaraniewski and
mfranczy
as code owners
November 14, 2026 21:25
This branch has not been deployed
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.
Store.DeleteReferenceallocated its new slice with capacitylen(mapping.References)-1, which is -1 (makeslice:cap out of range, see the added test) when the owner mapping has no references yet.This PR changes it to use
len(mapping.References).What issue type does this pull request address? (keep at least one, remove the others)
/kind bugfix
What does this pull request do? Which issues does it resolve? (use
resolves #<issue_number>if possible)No related issue.
Please provide a short message that should be published in the vcluster release notes
Fixed a potential panic in the mappings store when deleting a reference from a mapping that has no references.
What else do we need to know?
This is just a robustness fix. I can't see how a user could trigger the panic code, but
DeleteReferenceis part of the public interface insynccontext.Mapper, plus the fix is simple, so maybe worth to fix it.The fix allocates one extra slot of capacity. I assume it is ok. It could also be
max(len(mapping.References)-1, 0)if a more optimized code is preferred.Note
Low Risk
Small robustness fix in reference bookkeeping with no change to happy-path behavior; only avoids a panic on an edge case.
Overview
Fixes a panic in
Store.DeleteReferencewhen the owner mapping exists but has an emptyReferencesslice. The slice was preallocated with capacitylen(mapping.References)-1, which is -1 in that case and triggersmakeslice: cap out of range.The allocation now uses
len(mapping.References)(capacity 0 when there are no references), so deleting a reference that was never added remains a no-op as intended.Adds
TestDeleteReferenceWithoutReferencesto lock in that behavior and guard against regressions.Reviewed by Cursor Bugbot for commit f25ad09. Bugbot is set up for automated code reviews on this repo. Configure here.