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

Buffer Overflow? #652

Open
5 of 6 tasks
wilwade opened this issue Sep 13, 2024 · 2 comments
Open
5 of 6 tasks

Buffer Overflow? #652

wilwade opened this issue Sep 13, 2024 · 2 comments
Labels
bug Something isn't working pending triage

Comments

@wilwade
Copy link

wilwade commented Sep 13, 2024

Acknowledgements

  • I read the documentation and searched existing issues to avoid duplicates
  • I understand this is a bug tracker and anything other than a proven bug will be closed
  • I understand this is a free project and relies on community contributions
  • I read and understood the Contribution guide

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.

let decoder = new TextDecoder("utf-8");
const zerosArray = new Array(1024).fill(0);
// @ts-ignore
const buf = Buffer.from(zerosArray);

Bugs are expected to be fixed by those affected by it

  • I'm interested in working on this issue

Compensating engineering work will speed up resolution and support the project

  • I'm willing to offer $10 for financial support
@wilwade wilwade added bug Something isn't working pending triage labels Sep 13, 2024
@shannonwells
Copy link

More info:

  • the behavior also occurs for Buffer.copyBytesFrom
  • the Buffer's ArrayBuffer is always 8192 in length, with a byteLength & length of whatever the original array length was, and a byteOffset = 4568 or something like it.
  • Instance method toString() outputs the correct values anyway
  • Instance method entries() also outputs the correct values
  • Does not occur when the same code is compiled into JS and then executed.

The workaround is to use Buffer.alloc with a TypedArray. Example:

const uint8array = new Uint8Array([0,1,2,3,5,8,13]);
const buf = Buffer.alloc(uint8array.length, uint8array)

The above results in the expected values in the Buffer's ArrayBuffer, with a length and byteLength of 7, byteOffset = 0 as expected.

@diracdeltas

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage
Projects
None yet
Development

No branches or pull requests

3 participants