emscripten-core / emscripten-core/emscripten

MEMFS crashes when writing large file

Open
#13,028 1 comment 0 reactions 0 assignees View on GitHub
good first bug help wanted wontfix
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

## Minimal example
```c
// test.c
#include

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.