Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

vkurchatkin
Copy link
Contributor

Pull Request check-list

  • Does make -j8 test (UNIX) or vcbuild test nosign (Windows) pass with
    this change (including linting)?
  • Is the commit message formatted according to CONTRIBUTING.md?
  • If this change fixes a bug (or a performance problem), is a regression
    test (or a benchmark) included?
  • Is a documentation update included (if this change modifies
    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 of
pooled allocation. In case of "slow" allocation it will be
set later anyway.

Fixes: #6006

@evanlucas
Copy link
Contributor

Maybe add a regression test?

@MylesBorins
Copy link
Contributor

Tested locally and can confirm this fixes master + v5

@jasnell
Copy link
Member

jasnell commented Apr 1, 2016

Regression test for sure. Otherwise LGTM.

@jasnell jasnell added the buffer Issues and PRs related to the buffer subsystem. label Apr 1, 2016
@cjihrig
Copy link
Contributor

cjihrig commented Apr 1, 2016

LGTM pending a test.

@vkurchatkin
Copy link
Contributor Author

Added some tests

assert(isZeroFilled(new Float64Array(10)));

Buffer.allocUnsafe(10);
assert(isZeroFilled(Buffer.alloc(10)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: missing newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

@evanlucas
Copy link
Contributor

LGTM if CI is happy

@jasnell
Copy link
Member

jasnell commented Apr 1, 2016

@MylesBorins
Copy link
Contributor

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;
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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
@jasnell
Copy link
Member

jasnell commented Apr 2, 2016

CI looks good. One unrelated failure.

jasnell pushed a commit that referenced this pull request Apr 2, 2016
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]>
@jasnell
Copy link
Member

jasnell commented Apr 2, 2016

Landed in 0dcb026

@jasnell
Copy link
Member

jasnell commented Apr 2, 2016

Will cherry-pick this into v5.x as well.

jasnell pushed a commit that referenced this pull request Apr 2, 2016
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]>
@indutny
Copy link
Member

indutny commented Apr 2, 2016

CVE?

This was referenced Apr 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First typed array is not zero-filled (v5.10.0)
6 participants