-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Deno corrupts WASM binaries downloaded via network #3528
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
Comments
Going through the source, I think the issue is as follows: Deno UTF8-encodes the source code downloaded. However, doing this to the WASM binary corrupts it in the same way observed above. To fix this, WASM module downloads would need to bypass the UTF8-encoding step. Example: const bytes = await Deno.readFile("add.wasm");
const utf8 = new TextDecoder().decode(bytes);
const bytes_out = new TextEncoder().encode(utf8);
console.log(bytes.length, bytes_out.length);
console.log(utf8); outputs:
|
I wonder this is a problem of our |
Yeah, I think that’s where the problem lies. From what I can tell, files should be moved around as I’m trying to get something like that to work, but I’m completely new to rust though, so the file fetcher and http_util thing is quite confusing 😅 |
Return raw bytes instead of string, addresses denoland#3528
Deno allows to import WASM files directly as per #2552. This works great for local files. However, if the files are downloaded via the network, they seem to be corrupted, resulting in compile errors.
How to reproduce
(tested on deno 0.26.0)
clang --target=wasm32 --no-standard-libraries -Wl,--no-entry -nostartfiles -Wl,--export-all -o add.wasm add.c
deno --allow-read --allow-net serve_wasm.js
deno import_xxx.js
Files
add.c
serve_wasm.js
import_local.js
import_net.js
import_cache.js
Some observations
Comparing the served files with the file in the cache there are some discrepancies:
And
cat
ing the files reveals that the cached version has a bunch of extra bytes:original
deno cache
The text was updated successfully, but these errors were encountered: