TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Does Compiling to WebAssembly Prevent Issues with Unsafe Languages?

2 点作者 devtailz超过 1 年前

3 条评论

averageValentin超过 1 年前
Compiling to WebAssembly can mitigate certain issues, specificaly with memory safety in unsafe languages like C.<p>Take this C function: void write_to_buffer(char *buffer, unsigned int size, char value) { for (unsigned int i = 0; i &lt;= size; ++i) { buffer[i] = value; &#x2F;&#x2F; Unsafe: can write past the buffer if size is too large } }<p>Compiled to native code, an incorect size can lead to a buffer overflow. However, if you compile this to WebAssembly, the out-of-bounds write would be caught by the WebAssembly runtime, preventing a potential security flaw. But it doesn&#x27;t eliminate the need for good coding practices, it does add a layer of protection against some kinds of memory-related errors
评论 #38129523 未加载
syrusakbary超过 1 年前
It does solve many of the issues, namely:<p><pre><code> * Memory isolation (memory can&#x27;t be executable, and thus you reduce injection attacks). * Sandboxing: by default Wasm has no access to the outer universe where is being called, this makes quite trivial to properly sandbox almost any kind of program (on the systemcall layer) </code></pre> And it does so without requiring hardware virtualization
fwsgonzo超过 1 年前
Yes, so can any type of userspace sandboxing with speculation safe emulators. Virtualization also prevents these issues.<p>So, you can safely use C from your gameboy emulator, RISC-V emulator, or WebAssembly emulator. The quality of the emulator determines how much information you get back when something happens.