Repository navigation
Potential fix for code scanning alert no. 22: Size computation for allocation may overflow - #252
Merged
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Paulo Gomes <paulo.gomes.uk@gmail.com>
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the allocation-capacity guard in Namespace.Enter.
No open issues 🎉
What changed in this PR
This PR guards the allocation-capacity calculation in Namespace.Enter, targeting the reported overflow risk when wrapping sandbox arguments.
Changes:
- Checks
len(args)againstmath.MaxInt-prefixbefore adding the prefix length. - Preserves preallocation for normal inputs and uses zero initial capacity otherwise, without changing the method signature or argument order.
| File | Description |
|---|---|
internal/session/session.go |
Imports math and guards the slice-capacity calculation in Namespace.Enter. |
Review effort: Balanced
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.
Potential fix for https://github.com/qubesome/cli/security/code-scanning/22
To fix this class of issue, guard all size arithmetic used for allocation capacity before calling
makeorappendwith pre-sized backing arrays. Specifically, before computingprefix+len(args), check thatlen(args) <= math.MaxInt-prefix; if not, fail safely (or degrade to non-preallocated append path). This preserves behavior for normal inputs and prevents overflow/panic on pathological inputs.Best minimal fix (without changing existing functionality/signatures) is in
internal/session/session.goinsideNamespace.Enter:mathimport.make(..., prefix+len(args))with guarded capacity calculation:capHint := 0capHint = prefix + len(args)make([]string, 0, capHint).This avoids overflow while keeping normal preallocation optimization when safe.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.