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.allocUnsafe with randomFillSync is broken in Node.js 15.0.0 #3033

Closed
Zabrah opened this issue Oct 20, 2020 · 2 comments
Closed

Buffer.allocUnsafe with randomFillSync is broken in Node.js 15.0.0 #3033

Zabrah opened this issue Oct 20, 2020 · 2 comments

Comments

@Zabrah
Copy link

Zabrah commented Oct 20, 2020

  • Node.js Version: 15.0.0
  • OS: macOS 10.15.7
  • Scope (install, code, runtime, meta, other?): runtime
  • Module (and version) (if relevant): buffer, crypto

In the new Node.js 15.0.0 the use of Buffer.allocUnsafe gives a zero-filled Buffer, like with Buffer.alloc.
This kind of Buffer can be filled will buf.fill or manipulated by buf.writeUInt8. But it cannot be filled with crypto.randomFillSync(buf). If this is tried, the Buffer keeps its previously content.
By using asynchronous randomFill or still the Sync-one but with Buffer.alloc this problem does not appear.

const crypto = require("crypto");
const buf = Buffer.allocUnsafe(4);
console.log(buf);             //--> <Buffer 00 00 00 00>
buf.fill(255);
console.log(buf);             //--> <Buffer ff ff ff ff>
crypto.randomFillSync(buf);
console.log(buf);             //--> <Buffer ff ff ff ff>
@richardlau
Copy link
Member

Being addressed by nodejs/node#35723. See also reported issue over in nodejs/node#35722

@Zabrah
Copy link
Author

Zabrah commented Oct 20, 2020

Oh, ok. Didn't searched there. Thanks for the info.

@Zabrah Zabrah closed this as completed Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants