Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Use Buffer.allocUnsafe instead of the deprecated new Buffer() #3985

Merged
merged 1 commit into from
Jun 26, 2018
Merged

Use Buffer.allocUnsafe instead of the deprecated new Buffer() #3985

merged 1 commit into from
Jun 26, 2018

Conversation

NaridaL
Copy link
Contributor

@NaridaL NaridaL commented Jun 21, 2018

(node:16148) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
allocUnsafe should be fine because in both cases, the buffer is immediately filled and thrown out.

PR checklist

  • Addresses an existing issue: #0000
  • bugfix
  • Includes tests
  • Documentation update

Overview of change:

Is there anything you'd like reviewers to focus on?

CHANGELOG.md entry:

(node:16148) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
allocUnsafe should be fine because in both cases, the buffer is immediately filled and thrown out.
@@ -66,7 +66,7 @@ function showEncoding(encoding: Encoding): string {
function detectEncoding(fileName: string): Encoding {
const fd = fs.openSync(fileName, "r");
const maxBytesRead = 3; // Only need 3 bytes to detect the encoding.
const buffer = new Buffer(maxBytesRead);
const buffer = Buffer.allocUnsafe(maxBytesRead);
Copy link

@giladgray giladgray Jun 26, 2018

Choose a reason for hiding this comment

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

@NaridaL is there a not "unsafe" alternative? i'm not familiar with these internals.

@NaridaL
Copy link
Contributor Author

NaridaL commented Jun 26, 2018

The underlying memory for Buffer instances created in this way is not initialized. The contents of the newly created Buffer are unknown and may contain sensitive data. Use Buffer.alloc() instead to initialize Buffer instances with zeroes.

In both cases, the buffer is immediately initialized with file contents, nothing is output to the user, and I'm not currently seeing any situation where tslint has access to sensitive data the user doesn't have access to anyway. allocUnsafe should be fine.

Copy link

@giladgray giladgray left a comment

Choose a reason for hiding this comment

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

thanks for the explanation

@giladgray giladgray merged commit c01bb2c into palantir:master Jun 26, 2018
pablobirukov pushed a commit to evolution-gaming/tslint that referenced this pull request Jul 4, 2018
…ir#3985)

(node:16148) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
allocUnsafe should be fine because in both cases, the buffer is immediately filled and thrown out.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants