Version of emscripten/emsdk:
Calling posix_fallocate(fd, offset, len) with offset + len past Number.MAX_SAFE_INTEGER (2^53 − 1) throws a RangeError and kills the whole wasm instance.
Failing command line in full:
$ emcc -O0 -Wall fallocate.c -o a.out.js
$ node a.out.js
a.out.js:1518
node.contents = new Uint8Array(newSize); // Allocate new storage.
^
RangeError: Invalid typed array length: 9007199254740996
at new Uint8Array (<anonymous>)
at Object.resizeFileStorage (a.out.js:1518:25)
at setattr (a.out.js:1558:19)
at Object.doSetAttr (a.out.js:2341:9)
at Object.doTruncate (a.out.js:2829:12)
at Object.ftruncate (a.out.js:2852:12)
at ___syscall_fallocate (a.out.js:944:12)
at wasm://wasm/00010f56:wasm-function[38]:0xd46
at wasm://wasm/00010f56:wasm-function[11]:0x41c
at wasm://wasm/00010f56:wasm-function[12]:0x529
The same program on native Linux prints ret=27 errno=0 and exits cleanly.
Example code snippet:
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(void) {
int fd = open("/tmp/x", O_RDWR | O_CREAT | O_TRUNC, 0644);
off_t off = (off_t)1 << 53;
int ret = posix_fallocate(fd, off, 3);
printf("ret=%d errno=%d (%s)\n", ret, errno, strerror(errno));
close(fd);
return 0;
}
Version of emscripten/emsdk:
Calling
posix_fallocate(fd, offset, len)withoffset + lenpastNumber.MAX_SAFE_INTEGER(2^53 − 1) throws aRangeErrorand kills the whole wasm instance.Failing command line in full:
The same program on native Linux prints
ret=27 errno=0and exits cleanly.Example code snippet: