-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Deno v1.14: readFileSync returns an Uint8Array whose underlying buffer is null-terminated #12298
Comments
It looks like we have the same problem. The version where the bug first appeared was 1.14.1, and everything is normal in 1.14.0 When I tried to use @swc/wasm-web to create a transcoding server, an exception occurred when importing the wasm file
I was not sure whether it was a deno or swc bug before, now I’m sure it’s a deno problem, both Deno.readFile and Deno.readFileSync are affected. |
#12057 is the change that's responsible but I wouldn't call it a bug. The only guarantee is that the edit: what are the odds of two people commenting at exactly same time after 5 days... |
const buffer = new ArrayBuffer(42);
const uint8 = new Uint8Array(buffer);
console.log( uint8.length , buffer.byteLength , uint8.length === buffer.byteLength );
// 42 42 true They are 1-to-1 match, the problem is only in Deno.readFile and Deno.readFileSync. |
In general, you can't expect a const buffer = new ArrayBuffer(1024);
const view = new Uint8Array(buffer, 0, 42);
yourCode(view); And @autoxbc in particular seems to be creating a const {module, instance} = await WebAssembly.instantiateStreaming(
await new Response(await Deno.readFile("/path/to/file.wasm"))
); (Not to mention that, if you're not actually fetching a wasm module from the network, you should instead use const {module, instance} = await WebAssembly.instantiate(await Deno.readFile("/path/to/file.wasm")); |
Right, I updated my own code to work with the Uint8Array itself (and handle the offset & length as needed) instead of grabbing the underlying ArrayBuffer and assuming it can be used in full. Feel free to close if you consider the previous behavior an implementation detail that users shouldn't rely on, seems fair enough to me. |
const input = Deno.readFileSync('./test.js');
const { buffer } = input ;
const output = new Uint8Array(buffer);
console.log( input.length === output.length );
// false This caused confusion.
Slice out a new |
|
OK, it works, thank you. |
Hi!
The underlying
ArrayBuffer
of theUint8Array
returned byDeno.readFileSync()
is null-terminated in v1.14 but wasn't in v1.13.Since this change just caused a bug in my project, I was wondering if this is an expected change (and I need to update my code) or whether it should be fixed in Deno?
test.txt
can be just the lettera
for instance.In Deno v1.13, this prints:
1 1 true
(buffer contains"a"
)In Deno v1.14, it now prints:
1 2 false
(buffer contains"a\0"
)The text was updated successfully, but these errors were encountered: