-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
fix: ftruncate for negative and maximum values #35645
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
Changes from all commits
41ca10a
9694783
e861776
7688f6c
ffb1861
e04fd9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,7 +35,6 @@ const kIoMaxLength = 2 ** 31 - 1; | |||||||||||||||
| const { | ||||||||||||||||
| ArrayPrototypePush, | ||||||||||||||||
| BigIntPrototypeToString, | ||||||||||||||||
| MathMax, | ||||||||||||||||
| Number, | ||||||||||||||||
| NumberIsSafeInteger, | ||||||||||||||||
| ObjectCreate, | ||||||||||||||||
|
|
@@ -845,7 +844,11 @@ function ftruncate(fd, len = 0, callback) { | |||||||||||||||
| } | ||||||||||||||||
| validateInt32(fd, 'fd', 0); | ||||||||||||||||
| validateInteger(len, 'len'); | ||||||||||||||||
| len = MathMax(0, len); | ||||||||||||||||
|
|
||||||||||||||||
| if (len < 0) { | ||||||||||||||||
| throw new ERR_INVALID_ARG_VALUE('len', len); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
846
to
+851
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we throw a
Suggested change
|
||||||||||||||||
| callback = makeCallback(callback); | ||||||||||||||||
|
|
||||||||||||||||
| const req = new FSReqCallback(); | ||||||||||||||||
|
|
@@ -856,7 +859,11 @@ function ftruncate(fd, len = 0, callback) { | |||||||||||||||
| function ftruncateSync(fd, len = 0) { | ||||||||||||||||
| validateInt32(fd, 'fd', 0); | ||||||||||||||||
| validateInteger(len, 'len'); | ||||||||||||||||
| len = MathMax(0, len); | ||||||||||||||||
|
|
||||||||||||||||
| if (len < 0) { | ||||||||||||||||
| throw new ERR_INVALID_ARG_VALUE('len', len); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
861
to
+866
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we throw a
Suggested change
|
||||||||||||||||
| const ctx = {}; | ||||||||||||||||
| binding.ftruncate(fd, len, undefined, ctx); | ||||||||||||||||
| handleErrorFromBinding(ctx); | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -224,13 +224,14 @@ function testFtruncate(cb) { | |||||||||
| } | ||||||||||
|
|
||||||||||
| { | ||||||||||
| const file6 = path.resolve(tmp, 'truncate-file-6.txt'); | ||||||||||
| fs.writeFileSync(file6, 'Hi'); | ||||||||||
| const fd = fs.openSync(file6, 'r+'); | ||||||||||
| process.on('beforeExit', () => fs.closeSync(fd)); | ||||||||||
| fs.ftruncate(fd, -1, common.mustSucceed(() => { | ||||||||||
| assert(fs.readFileSync(file6).equals(Buffer.from(''))); | ||||||||||
| })); | ||||||||||
| assert.throws( | ||||||||||
| () => fs.ftruncate(fd, -1), | ||||||||||
| { | ||||||||||
| code: 'ERR_INVALID_ARG_VALUE', | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| name: /(TypeError|RangeError)/, | ||||||||||
| message: 'The argument \'len\' is invalid. Received -1' | ||||||||||
| } | ||||||||||
| ); | ||||||||||
|
Comment on lines
+227
to
+234
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IgorHalfeld The node/test/parallel/test-fs-truncate.js Line 71 in 7efada6
Instead of replacing the previous test completely, consider replacing only this part with your test (you may take a look at the other tests for help): node/test/parallel/test-fs-truncate.js Lines 231 to 233 in 7efada6
Also, Similarly, consider adding a corresponding test for |
||||||||||
| } | ||||||||||
|
|
||||||||||
| { | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.