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

Invalid buffers not throwing warnings #6770

Closed
jspri opened this issue May 15, 2016 · 3 comments
Closed

Invalid buffers not throwing warnings #6770

jspri opened this issue May 15, 2016 · 3 comments
Labels
buffer Issues and PRs related to the buffer subsystem.

Comments

@jspri
Copy link
Contributor

jspri commented May 15, 2016

  • Version: v6.1.0
  • Platform: Win10 x64

var a = new Buffer('1', 'hex') creates a new empty buffer. This throws an error on earlier versions of node (tested on v5.8) as the input length should be a multiple of 1 byte.

Probably introduced by afd821a in lib/buffer.js. The length check returns 0 which would have normally gone on to raise an error at a later stage but is now short circuited by the new code.

Could probably just do with an extra line to check if the input is non empty or have byteLength return a fractional value.

@addaleax addaleax added the buffer Issues and PRs related to the buffer subsystem. label May 15, 2016
@addaleax
Copy link
Member

Probably introduced by afd821a in lib/buffer.js.

Yep, can confirm that.

Could probably just do with an extra line to check if the input is non empty

Yeah, I think that’s the right thing to do (maybe even instead of/before the byteLength calculation, as @ronkorving’s comment on afd821a suggests). Interested in writing a PR for that?

/cc @nodejs/buffer

@jspri
Copy link
Contributor Author

jspri commented May 15, 2016

Sure, I'll do a PR. Is this the sort of thing you would normally also write a test case for?

@addaleax
Copy link
Member

Yes, definitely. You can see an example of a test for that in e.g. #4877, which comes pretty close to what you are going to test here.

jspri added a commit to jspri/node that referenced this issue May 15, 2016
@jspri jspri mentioned this issue May 15, 2016
4 tasks
Fishrock123 pushed a commit that referenced this issue May 23, 2016
Fixes single digit hex strings not raising TypeError on Buffer creation.

Fixes: #6770
PR-URL: #6775
Reviewed-By: Anna Henningsen <anna@addaleax.net>
rvagg pushed a commit that referenced this issue Jun 2, 2016
Fixes single digit hex strings not raising TypeError on Buffer creation.

Fixes: #6770
PR-URL: #6775
Reviewed-By: Anna Henningsen <anna@addaleax.net>
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

No branches or pull requests

2 participants