emscripten-core/emscripten

MEMFS crashes when writing large file

Open

#13,028 创建于 2020年12月13日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)C++ (3,519 fork)batch import
good first bughelp wantedwontfix

仓库指标

Star
 (27,361 star)
PR 合并指标
 (平均合并 19天 10小时) (30 天内合并 147 个 PR)

描述

Minimal example

// test.c
#include <stdio.h>

int main() {
  FILE *fp = fopen("/tmp/test.txt", "w");
  fseek(fp, 2147483647, SEEK_SET);
  fputs("a", fp);
  fclose(fp);
  return 0;
}

Compiled with emcc with no options.

Actual behavior

Running this on firefox gives

RangeError: invalid array length

while running on Chromium gives

RangeError: Array buffer allocation failed

This happens when MEMFS tries to create a TypedArray that is too large.

Expected behavior

This should be treated as MEMFS running out of disk space and return appropriate errors to wasm.

See also #11381

贡献者指南