Skip to content

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

Closed

Description

@Zabrah
  • 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>

Activity

  1. richardlau commented on Oct 20, 2020

    @richardlau
    Member

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

  2. Zabrah commented on Oct 20, 2020

    @Zabrah
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions