fix(core): enforce bounds checking for LeakageStatus qubit indices - #1
Open
mertcano wants to merge 1 commit into
Open
fix(core): enforce bounds checking for LeakageStatus qubit indices#1mertcano wants to merge 1 commit into
mertcano wants to merge 1 commit into
Conversation
### Description This PR addresses a native memory safety vulnerability within the `LeakageStatus` operations. Previously, passing an out-of-range index from Python could reach undefined native behavior due to unchecked vector access. ### Key Changes * **Safe Vector Access (`status.cc`):** * The `set`, `reset`, `get`, and `is_leaked` methods have been updated to use the bounds-checked `s.at(qubit)` method instead of unchecked array indexing[cite: 35]. * This guarantees that any out-of-bounds access attempt will be safely caught at the C++ level before causing memory corruption[cite: 35]. ### Validation & Testing * **Regression Testing (`leaky_pybind_test.py`):** * Added the `test_leakage_status_rejects_out_of_range_indices` regression test[cite: 36]. * This test explicitly verifies that calling `set`, `reset`, `get`, or `is_leaked` with an invalid index (e.g., index `2` for a status of length `2`) correctly raises an `IndexError` in Python[cite: 36].
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.
Description
This PR addresses a native memory safety vulnerability within the
LeakageStatusoperations. Previously, passing an out-of-range index from Python could reach undefined native behavior due to unchecked vector access.Key Changes
status.cc):set,reset,get, andis_leakedmethods have been updated to use the bounds-checkeds.at(qubit)method instead of unchecked array indexing[cite: 35].Validation & Testing
leaky_pybind_test.py):test_leakage_status_rejects_out_of_range_indicesregression test[cite: 36].set,reset,get, oris_leakedwith an invalid index (e.g., index2for a status of length2) correctly raises anIndexErrorin Python[cite: 36].