emscripten-core/emscripten

MEMFS crashes when writing large file

開放

#13,028 建立於 2020年12月13日

 (1 則留言) (0 個反應) (0 位負責人)C++ (3,519 個分叉)batch import
good first bughelp wantedwontfix

倉庫指標

星標
 (27,361 顆星)
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

貢獻者指南