Skip to content

Potential fix for code scanning alert no. 22: Size computation for allocation may overflow - #252

Merged
pjbgf merged 1 commit into
mainfrom
alert-autofix-22
Nov 18, 2026
Merged

pjbgf merged 1 commit into
mainfrom
alert-autofix-22

Conversation

@pjbgf

@pjbgf pjbgf commented Nov 18, 2026

Copy link
Copy Markdown
Member

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 make or append with pre-sized backing arrays. Specifically, before computing prefix+len(args), check that len(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.go inside Namespace.Enter:

  • Add math import.
  • Replace direct make(..., prefix+len(args)) with guarded capacity calculation:
    • default capHint := 0
    • if safe, set capHint = prefix + len(args)
    • allocate with make([]string, 0, capHint).
      This avoids overflow while keeping normal preallocation optimization when safe.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

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>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:33
@pjbgf
pjbgf marked this pull request as ready for review November 18, 2026 13:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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) against math.MaxInt-prefix before 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

@pjbgf
pjbgf merged commit ad9d293 into main Nov 18, 2026
6 checks passed
@pjbgf
pjbgf deleted the alert-autofix-22 branch November 18, 2026 13:37
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