Skip to content

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

Merged
vinodvx merged 1 commit into
mainfrom
alert-autofix-3
Oct 6, 2026
Merged

vinodvx merged 1 commit into
mainfrom
alert-autofix-3

Conversation

@vinodvx

@vinodvx vinodvx commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Potential fix for https://github.com/agenticenv/durable-go/security/code-scanning/3

Add an overflow guard before the allocation in wrapSidecarMAC in journal.go.

General approach:

  • Before computing len(body)+len(mac) for allocation, verify it cannot overflow int.
  • If it would overflow, fail safely instead of allocating.

Best fix here (minimal functional impact):

  • len(mac) is fixed (sha256.Size) when MAC is enabled, but using generic guard is cleaner.
  • Change wrapSidecarMAC to return ([]byte, error) and guard with:
    • if len(body) > math.MaxInt-len(mac) { return nil, fmt.Errorf(...) }
  • Update call site in saveMeta to handle the returned error.
  • This preserves existing behavior for valid sizes and prevents panic/undersized allocation on overflow.

Files/regions to change:

  • journal.go
    • import block: add math
    • saveMeta: handle error from wrapSidecarMAC
    • wrapSidecarMAC: change signature and add overflow check

No changes are required in task.go; its alert variant flows into the same vulnerable allocation, so fixing wrapSidecarMAC addresses both.

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

…ocation may overflow

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@vinodvx
vinodvx marked this pull request as ready for review October 6, 2026 00:01
@vinodvx
vinodvx merged commit cb28305 into main Oct 6, 2026
4 of 6 checks passed
@vinodvx
vinodvx deleted the alert-autofix-3 branch October 6, 2026 00:06
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.

1 participant