Fix stack-use-after-return in test cpp_extension arrayref bindings#183781
Fix stack-use-after-return in test cpp_extension arrayref bindings#183781jeffdaily wants to merge 1 commit into
Conversation
The two pybind lambdas
m.def("get_intarrayref", []() { return at::IntArrayRef({1, 2, 3}); });
m.def("get_symintarrayref",[]() { return at::SymIntArrayRef({1, 2, 3}); });
return non-owning `ArrayRef` views of a `std::initializer_list` that lives on the lambda's stack. By the time pybind11's type-caster reads the data (e.g. `THPUtils_packInt64Array` walking the `int64_t*` to build a Python tuple), the lambda has unwound and the storage is gone. ASAN catches it as `stack-use-after-return` in `test/test_cpp_extensions_aot_*.py::TestPybindTypeCasters::test_pybind_return_types`.
Back the values with static storage so the `ArrayRef` views remain valid for the lifetime of the program. The intent of the test (exercising the type-caster for these two types) is preserved; only the storage class changes.
Authored with Claude.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/183781
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 1 New Failure, 22 Pending, 1 Unrelated FailureAs of commit 96daecb with merge base a1cc64b ( NEW FAILURE - The following job has failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: pull / linux-jammy-py3.14-clang18 / test (default, 4, 5, linux.4xlarge) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
The |
The two pybind lambdas
return non-owning
ArrayRefviews of astd::initializer_listthat lives on the lambda's stack. By the time pybind11's type-caster reads the data (e.g.THPUtils_packInt64Arraywalking theint64_t*to build a Python tuple), the lambda has unwound and the storage is gone. ASAN catches it asstack-use-after-returnintest/test_cpp_extensions_aot_*.py::TestPybindTypeCasters::test_pybind_return_types.Back the values with static storage so the
ArrayRefviews remain valid for the lifetime of the program. The intent of the test (exercising the type-caster for these two types) is preserved; only the storage class changes.Authored with Claude.