Closed
Description
fs.ftruncate and fd.ftruncateSync both silently ignore negative offsets:
Line 840 in 2cfdf28
This didn't always do behave like this.. looks like it was introduced in 8974df1
What steps will reproduce the bug?
var fs = require("fs");
var fd = fs.openSync("f", 'w+');
console.log(fs.ftruncateSync(fd, -99));
What is the expected behavior?
The ftruncate POSIX function is described as returning EINVAL when given a negative offset:
https://linux.die.net/man/2/ftruncate
In emscripten we emulate a POSIX environment on top of the Web and on top of node and expect ftruncate to fail in the same way.
We can obviously add a check to our code as a workaround but this does seem like a bug in node.
What do you see instead?
Silently assumed 0
length is what the caller really wants.