-
Notifications
You must be signed in to change notification settings - Fork 24
Fix Use-After-Free in NumPy/df #478
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,10 +29,14 @@ def podvector_to_numpy(self, copy=False): | |
| if copy: | ||
| # This supports a device-to-host copy. | ||
| # | ||
| # todo: validate of the to_host() returned object | ||
| # lifetime is always managed correctly by | ||
| # Python's GC - otherwise copy twice via copy=True | ||
| return np.array(self.to_host(), copy=False) | ||
| # The to_host() returned object is a temporary, and | ||
| # np.array using the __array_interface__ protocol does | ||
| # not keep it alive automatically unless it is stored | ||
| # in an actual variable (tmp). | ||
| tmp = self.to_host() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, looks like there is more / this is not a sufficient fix (at least for some SP tests on conda-forge): It already has an issue here, so the problem could be in the implementation of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very hard to reproduce locally... also cannot spot anything in valgrind yet.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems to be fixed by BLAST-ImpactX/impactx#1156 o.0 |
||
| ret = np.array(tmp, copy=False) | ||
| assert ret.base is tmp | ||
| return ret | ||
| else: | ||
| return np.array(self, copy=False) | ||
| else: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
We can generally make this a bit more explicit by checking if
selfis on GPU and otherwise just copying from it directly, with anotherif/elsebranch. But the logic here should have the same effect and amount of copies involved...The only difference is that here we will always end up with pinned memory, while we might be sometimes interested using regular host memory. But seems niche.