Skip to content

semaphore: panic on negative weights#31

Closed
ZainYoussef wants to merge 1 commit into
golang:masterfrom
ZainYoussef:fix-negative-weights
Closed

semaphore: panic on negative weights#31
ZainYoussef wants to merge 1 commit into
golang:masterfrom
ZainYoussef:fix-negative-weights

Conversation

@ZainYoussef

Copy link
Copy Markdown
Contributor

The semaphore.Weighted API accepts int64 for weights. If a negative
weight is passed, it mathematically corrupts the internal state tracker
(s.cur) and bypasses the package's existing safety checks.

This adds strict boundary validation to panic immediately if a negative
weight is provided.

Fixes golang/go#80183

@google-cla

google-cla Bot commented Jul 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ZainYoussef ZainYoussef force-pushed the fix-negative-weights branch from dc49db9 to 8e7d04e Compare July 1, 2026 07:45
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 8e7d04e) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/sync/+/796080.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@ZainYoussef ZainYoussef force-pushed the fix-negative-weights branch from 8e7d04e to 1964698 Compare July 1, 2026 12:21
@gopherbot

Copy link
Copy Markdown
Contributor

Message from Alan Donovan:

Patch Set 1: Code-Review+2

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Alan Donovan:

Patch Set 1: -Code-Review


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 1964698) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/sync/+/796080.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@ZainYoussef ZainYoussef force-pushed the fix-negative-weights branch from 1964698 to ee6289c Compare July 1, 2026 12:28
@gopherbot

Copy link
Copy Markdown
Contributor

Message from Alan Donovan:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: ee6289c) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/sync/+/796080.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Zain Yousef:

Patch Set 2:

(3 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Alan Donovan:

Patch Set 3: Auto-Submit+1 Code-Review+2 Commit-Queue+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-07-01T13:21:25Z","revision":"51d829c5cefbb71c50fd06184caf21f4a7ddc3d4"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Alan Donovan:

Patch Set 3: -Commit-Queue

(Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_57259>)


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3:

This CL has passed the run


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3: LUCI-TryBot-Result+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Damien Neil:

Patch Set 3: Code-Review+2

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/796080.
After addressing review feedback, remember to publish your drafts!

The semaphore.Weighted API accepts int64 for weights. If a negative weight is passed, it mathematically corrupts the internal state tracker (s.cur) and bypasses the package's existing safety checks.

This adds strict boundary validation to panic immediately if a negative weight is provided.

Fixes golang/go#80183
@ZainYoussef ZainYoussef force-pushed the fix-negative-weights branch from ee6289c to f19eea2 Compare July 1, 2026 17:17
gopherbot pushed a commit that referenced this pull request Jul 1, 2026
The semaphore.Weighted API accepts int64 for weights. If a negative
weight is passed, it mathematically corrupts the internal state tracker
(s.cur) and bypasses the package's existing safety checks.

This adds strict boundary validation to panic immediately if a negative
weight is provided.

Fixes golang/go#80183

Change-Id: I7e74bad404a8b99aef7e3d2189dda43f8ea644c2
GitHub-Last-Rev: ee6289c
GitHub-Pull-Request: #31
Reviewed-on: https://go-review.googlesource.com/c/sync/+/796080
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Zain Yousef <zain.19dj@gmail.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
@ZainYoussef ZainYoussef closed this Jul 1, 2026
@gopherbot

Copy link
Copy Markdown
Contributor

This PR is being closed because golang.org/cl/796080 has been merged.

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.

x/sync/semaphore: Release and Acquire with negative weights bypass safeguards and corrupt internal state

2 participants