-
Notifications
You must be signed in to change notification settings - Fork 620
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
Fix access to unitialized memory in RNG ops #5394
Conversation
Operator used vector of reintereted bytes with assignment of std::distribution object carrying some state. Switch to a vector so the copy and move are not UB. Signed-off-by: Krzysztof Lecki <[email protected]>
CI MESSAGE: [13784528]: BUILD STARTED |
CI MESSAGE: [13784528]: BUILD FAILED |
dists_cpu.resize(sizeof(Dist) * nsamples); // memory was already reserved in the constructor | ||
Dist* dists = reinterpret_cast<Dist*>(dists_cpu.data()); | ||
bool use_default_dist = !This().template SetupDists<T>(dists, ws, nsamples); | ||
std::vector<Dist> dists(nsamples); |
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 is captured by value in task lambdas (see line 162 and 180).
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.
Please capture the distribution vector by reference or return to the use of a pointer.
Same fix with less allocations reimplemented in #5395 |
Category: Bug fix
Description:
Random operators used vector of reinterpreted bytes as a target of assignment when creating distribution objects.
The random choice uses non-trivial
std::discrete_distribution
carrying some state. Assigning to that memory caused a leak.Switch to a proper
vector<distribution>
, so the copy/move assignments are not UB as the location that we assign to is nowproperly constructed ahead of time.
Additional information:
Affected modules and functionalities:
RNG operators
Key points relevant for the review:
Tests:
The relevant fn.random.choice tests no longer report leak under ASAN.
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A