Repository navigation
Conversation
Return 1 early in tfq::GetBlockSize when output_size <= 0, context or context->device() is null, or tensorflow_cpu_worker_threads() is null or has non-positive num_threads, and clamp positive floor division to at least 1. Update the header contract, clean up IWYU includes, and add hermetic C++ unit tests covering null context/device, short-circuiting, null or non-positive worker threads, floor-division clamping, and single-thread execution.
mhucka
marked this pull request as ready for review
October 28, 2026 02:30
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of the GetBlockSize utility function in tfq_simulate_utils.cc by adding validation checks for null pointers, non-positive output sizes, and invalid thread counts. It also updates the function's documentation and introduces a comprehensive suite of unit tests in tfq_simulate_utils_test.cc to verify these edge cases. No review comments were provided, so there is no feedback to address.
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 b/510434542: null pointer dereference and division by zero in
GetBlockSizeintensorflow_quantum/core/ops/tfq_simulate_utils.cc.The change is to return 1 in
tfq_simulate_utils.ccwhenever certain conditions hold, and otherwise return a value that preservesstd::max(output_size / num_threads, 1). This PR also adds a test file fortest_simulate_utils.cc.This PR was developed with the help of Google Gemini.