-
-
Notifications
You must be signed in to change notification settings - Fork 170
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 Overflow? #652
Comments
More info:
The workaround is to use Buffer.alloc with a TypedArray. Example:
The above results in the expected values in the Buffer's ArrayBuffer, with a length and byteLength of 7, byteOffset = 0 as expected. |
This comment has been minimized.
This comment has been minimized.
Okay, this seems to be related to const buf1 = Buffer.from('hello')
console.log(new TextDecoder().decode(buf1.buffer))
// outputs "hello" is because there's no other data in a buffer in that JS - its pretty straightforward to duplicate with the following: const buf0 = Buffer.from("I'm some other text that you didn't expect!")
const buf1 = Buffer.from('hello')
console.log(new TextDecoder().decode(buf1.buffer))
// outputs "/I'm some other text that you didn't expect!hello" You can prevent this from happening with (what I'm sure is a pretty significant performance penalty) but setting const buf0 = Buffer.from("I'm some other text that you didn't expect!")
Buffer.poolSize = 1
const buf1 = Buffer.from('hello')
console.log(new TextDecoder().decode(buf1.buffer))
// outputs "hello" I think this might just be working as intended because I think this issue can probably be closed (even though the behavior is pretty counterintuitive). |
Acknowledgements
Minimal reproduction URL
https://gist.github.com/wilwade/66bc4614fdaa3a349c5f25b7164d12bc
Problem & expected behavior (under 200 words)
tsx Version: v4.19.1, v4.10.2
Note: This ALSO happens with ts-node v10.9.2
tldr: When using a buffer, the
buffer.buffer
is getting filled up with stuff it should not be.Bugs are expected to be fixed by those affected by it
Compensating engineering work will speed up resolution and support the project
The text was updated successfully, but these errors were encountered: