-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs.ftruncate silently accepts negative offsets rather than failing with ERR_INVALID #35632
Comments
Maybe removing |
What about adding this sort of a change? - len = MathMax(0, len);
+ if (len < 0) {
+ throw new ERR_FS_FILE_TOO_SMALL(len);
+ } else if (len > kIoMaxLength) {
+ throw new ERR_FS_FILE_TOO_LARGE(len);
+ } where, Lines 27 to 29 in 999e7d7
This would take care of both the upper and the lower limits for the allowed size in ftruncate .
|
I'm not familiar with node code but isn't there already the simple equivalent of |
Node |
`fs.ftruncate`, `fsPromises.truncate`, and `fsPromises.ftruncate` all adjust negative lengths to 0 before invoking the system call. `fs.truncate()` was the one outlier. This "fixes" nodejs#35632 but in the opposite direction than discussed in the issue -- specifically by removing an EINVAL error from one function rather than adding it to another. Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: nodejs#35632
PR: #37483 |
`fs.ftruncate`, `fsPromises.truncate`, and `fsPromises.ftruncate` all adjust negative lengths to 0 before invoking the system call. `fs.truncate()` was the one outlier. This "fixes" nodejs#35632 but in the opposite direction than discussed in the issue -- specifically by removing an EINVAL error from one function rather than adding it to another. Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: nodejs#35632
`fs.ftruncate`, `fsPromises.truncate`, and `fsPromises.ftruncate` all adjust negative lengths to 0 before invoking the system call. `fs.truncate()` was the one outlier. This "fixes" #35632 but in the opposite direction than discussed in the issue -- specifically by removing an EINVAL error from one function rather than adding it to another. Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: #35632 PR-URL: #37483 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
`fs.ftruncate`, `fsPromises.truncate`, and `fsPromises.ftruncate` all adjust negative lengths to 0 before invoking the system call. `fs.truncate()` was the one outlier. This "fixes" #35632 but in the opposite direction than discussed in the issue -- specifically by removing an EINVAL error from one function rather than adding it to another. Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: #35632 PR-URL: #37483 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
fs.ftruncate and fd.ftruncateSync both silently ignore negative offsets:
node/lib/fs.js
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?
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.The text was updated successfully, but these errors were encountered: