Repository navigation
Fix undefined behavior via unbounded left integer shifts - #1154
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 23, 2026 22:50
Contributor
There was a problem hiding this comment.
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.
MichaelBroughton
approved these changes
Nov 25, 2026
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.
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_cyclesor bitmasks using1 << max_num_qubitswheremax_num_qubitsis unvalidated.