-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
BUG: Added manual checks for self-nested sequences during array creation #29623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
BUG: Added manual checks for self-nested sequences during array creation #29623
Conversation
I believe that #29569 also addresses this, but I might be wrong |
/* Check for self-nested sequences to prevent RAM exhaustion */ | ||
if (is_sequence) { | ||
if (PySequence_Check(objects[0])) { | ||
if (objects[0] == obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still leaves
l = [[]]
l[0].append(l)
l[0].append(l)
np.array(l)
and 62 other cases like these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not that that's necessarily a problem, it's just something to be aware of)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I got u, this addresses only one specific and most common case of self-nesting. Thanks !
Previously, when creating a NumPy array with self-nested sequences, it causes a quick RAM exhaustion, as also described in #29620, all due to the cyclic recursions.
With these changes, when creating an array with sequences, a check for self-nesting is performed first, which prevents any further cyclic recursions.
Before:
Now:
closes #29620