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

behaviour of Buffer.from(string[, encoding]) is not specified for invalid input #24722

Closed
safareli opened this issue Nov 29, 2018 · 5 comments
Closed
Labels
buffer Issues and PRs related to the buffer subsystem. feature request Issues that request new features to be added to Node.js. stale

Comments

@safareli
Copy link

for example

➜  node
> Buffer.from("LOL", "hex")
<Buffer >
> Buffer.from("LOL#$%^&*(", "hex")
<Buffer >
> Buffer.byteLength("LOL#$%^&*(", "hex")
5
> Buffer.byteLength("0x8", "hex")
1
> Buffer.from("0x8", "hex")
<Buffer >
> Buffer.from("qqq0x8123132", "hex")
<Buffer >
> Buffer.from("110x8123132", "hex")
<Buffer 11>
> Buffer.from("1_-10x8123132", "hex")
<Buffer >

In general Buffer.from returns trash if input string is is not valid, and it could be a source if error/bugs. in node v7 this it was throwing TypeError: Invalid hex string but now it isn't.

  • Version:
    v8.12.0
  • Platform:
    Darwin Iraklis-MacBook-Pro-2.local 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64

Related to #8569 but it's not a feature request it's a bug report as I consider this to be a bug and instead of adding safeFrom this default one should be safe and if people need there should be unsafeFrom.

@bnoordhuis bnoordhuis added buffer Issues and PRs related to the buffer subsystem. feature request Issues that request new features to be added to Node.js. labels Nov 29, 2018
@bnoordhuis
Copy link
Member

See #3770 for rationale. Summary: the validation for 'hex' was only partial and inconsistently applied at that, so it was removed.

For example, Buffer.from('xx', 'hex') doesn't throw an exception in v7.x, it returns an empty buffer.

@bnoordhuis
Copy link
Member

Forgot to mention, changing the current behavior might have backwards compatibility implications.

Node.js has always* accepted Buffer.from('abcdefGH', 'hex') and produced a meaningful result (a three byte buffer containing AB CD EF) so it's quite possible programs or libraries exist that depend on that behavior.

* I'm fairly sure it goes back all the way to Node.js v0.1 or v0.2.

@mohd-akram
Copy link
Contributor

This is kinda insane tbh. Can this breaking change be done in Node.js 18 then?

@github-actions
Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label May 27, 2022
@github-actions
Copy link
Contributor

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@targos targos moved this from Pending Triage to Stale in Node.js feature requests Apr 4, 2023
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. feature request Issues that request new features to be added to Node.js. stale
Projects
None yet
Development

No branches or pull requests

3 participants