Skip to content

Fix undefined behavior via unbounded left integer shifts - #1154

Merged
mhucka merged 1 commit into
masterfrom
fix-left-shift-ub
Nov 25, 2026
Merged

mhucka merged 1 commit into
masterfrom
fix-left-shift-ub

Conversation

@mhucka

@mhucka mhucka commented Nov 23, 2026

Copy link
Copy Markdown
Member

This is a fix for the vulnerability reported in b/510434994, "Undefined Behavior and Crashes via Unbounded Left Integer Shifts". According to the report, multiple C++ files calculate num_cycles or bitmasks using 1 << max_num_qubits where max_num_qubits is unvalidated.

This is a fix for the vulnerability reported in b/510434994, "Undefined Behavior and Crashes via Unbounded Left Integer Shifts". According to the report, multiple C++ files calculate `num_cycles` or bitmasks using `1 << max_num_qubits` where `max_num_qubits` is unvalidated.
@mhucka mhucka added area/c++ Involves C++ code area/google-cybersecurity Security-related issues and PRs labels Nov 23, 2026
@mhucka
mhucka marked this pull request as ready for review November 23, 2026 22:50

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces safety checks, validation, and upper bounds on qubit counts across various simulation operations in TensorFlow Quantum to prevent undefined behavior (such as bit-shift overflows) and memory exhaustion. Key changes include defining limits for state-vector, unitary, and MPS simulations, implementing a ValidateNumQubits helper, using AddDimWithStatus for tensor dimension allocation, and adding safety checks for controlled gates and sampled expectations in the qsim integration. I have no feedback to provide as there are no review comments.

@mhucka
mhucka added this pull request to the merge queue Nov 25, 2026
Merged via the queue into master with commit 81a5763 Nov 25, 2026
13 checks passed
@mhucka
mhucka deleted the fix-left-shift-ub branch November 25, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/c++ Involves C++ code area/google-cybersecurity Security-related issues and PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants