-
Notifications
You must be signed in to change notification settings - Fork 30k
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
buffer: don't set kNoZeroFill
flag in allocUnsafe
#6007
Conversation
Maybe add a regression test? |
Tested locally and can confirm this fixes master + v5 |
Regression test for sure. Otherwise LGTM. |
LGTM pending a test. |
82396ea
to
6a3236a
Compare
Added some tests |
assert(isZeroFilled(new Float64Array(10))); | ||
|
||
Buffer.allocUnsafe(10); | ||
assert(isZeroFilled(Buffer.alloc(10))); |
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.
style: missing newline
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.
fixed!
LGTM if CI is happy |
LGTM |
@@ -7,8 +7,18 @@ const safe = Buffer.alloc(10); | |||
|
|||
function isZeroFilled(buf) { | |||
for (let n = 0; n < buf.length; n++) | |||
if (buf[n] > 0) return false; | |||
if (buf[n] !== 0) return false; |
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.
ha! sigh... I had uint8 on the brain I guess. good catch.
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.
Also -0
could be a factor, but I'm not sure. Any way, tests are a bit non-deterministic, since even if there is no actual zero filling, there is still a chance that some allocations would be zeros
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, that came up in the original review. It's not a great test. The plan was to revisit to see if the test can be made more robust.
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.
Also for some reason this bug is hard to reproduce with small Uint8Array
.
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.
Looking at it now this one should have been obvious :-/. The bug only shows up after doing a pooled unsafeAlloc allocation because the zero fill flag was never being reset (because a real allocation wasn't being done).
(update: ha! I see you noted that in your commit log... it's definitely a friday)
If `kNoZeroFill` is set here, it won't be reset in case of pooled allocation. In case of "slow" allocation it will be set later anyway. Fixes: nodejs#6006
6a3236a
to
abb9c4d
Compare
CI looks good. One unrelated failure. |
If `kNoZeroFill` is set here, it won't be reset in case of pooled allocation. In case of "slow" allocation it will be set later anyway. Fixes: #6006 PR-URL: #6007 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Myles Borins <[email protected]>
Landed in 0dcb026 |
Will cherry-pick this into v5.x as well. |
If `kNoZeroFill` is set here, it won't be reset in case of pooled allocation. In case of "slow" allocation it will be set later anyway. Fixes: #6006 PR-URL: #6007 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Myles Borins <[email protected]>
CVE? |
Pull Request check-list
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
Affected core subsystem(s)
buffer
Description of change
If
kNoZeroFill
is set here, it won't be reset in case ofpooled allocation. In case of "slow" allocation it will be
set later anyway.
Fixes: #6006