Repository navigation
BUG: avoid BitGenerator segfault after failed re-init (gh-28784) - #47
Draft
cursor[bot] wants to merge 2 commits into
Draft
cursor[bot] wants to merge 2 commits into
cursor[bot] wants to merge 2 commits into
Conversation
Validate the seed before mutating BitGenerator state so a failed re-__init__ cannot leave a NULL _bitgen.state. Add defensive checks in random_raw/Generator and validate Philox counter/key before applying. Co-authored-by: Kushagra Agarwal <[email protected]>
Co-authored-by: Kushagra Agarwal <[email protected]>
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.
PR summary
Fixes numpy/numpy#28784: re-running
BitGenerator.__init__with an invalid seed used to clear_bitgen.stateto NULL before seed validation, so a laterrandom_raw()segfaulted.Approach
SeedSequence-validate the seed before mutating instance state inBitGenerator.__init__, and stop clearing_bitgen.stateearly (subclasses install it).ValueErrorinrandom_raw/_benchmarkwhen callbacks/state were never installed.Generatorrejects incompletely initialized bit generators (also hardens the incomplete-subclass case from BUG: np.random.Generator(MyBitGenerator).random() segfaults every time numpy/numpy#25023).counter/keybefore applying them on (re)init.Test plan
spin test -v -t numpy/random/tests/test_regression.pyspin test -v -t numpy/random/testsspin test -v: 48741 passed, 345 skipped, 3647 deselected, 56 xfailed, 4 xpassedspin lint: passedUpstream issue: numpy#28784
First time committer introduction
Automated fork contribution targeting a high-impact Cython crash fix in
numpy.random.AI Disclosure
This pull request was prepared by a Cursor Cloud Agent (Cursor Grok 4.5). The Cython/Python code changes, regression tests, and PR text were AI-generated and then verified locally with
spin build, targeted random tests, fullspin test -v, andspin lint.