Skip to content

fix(core): enforce bounds checking for LeakageStatus qubit indices - #1

Open
mertcano wants to merge 1 commit into
Infleqtion:masterfrom
mertcano:mertcano-patch-1
Open

fix(core): enforce bounds checking for LeakageStatus qubit indices#1
mertcano wants to merge 1 commit into
Infleqtion:masterfrom
mertcano:mertcano-patch-1

Conversation

@mertcano

Copy link
Copy Markdown

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].

### 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].
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.

1 participant