| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6350d35 commit 9c06103
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -630,7 +630,7 @@ function read(fd, buffer, offset, length, position, callback) { | |||
| 630 | 630 | if (offset == null) { | |
| 631 | 631 | offset = 0; | |
| 632 | 632 | } else { | |
| 633 | - validateInteger(offset, 'offset'); | ||
| 633 | + validateInteger(offset, 'offset', 0); | ||
| 634 | 634 | } | |
| 635 | 635 | ||
| 636 | 636 | length |= 0; | |
@@ -694,7 +694,7 @@ function readSync(fd, buffer, offset, length, position) { | |||
| 694 | 694 | if (offset == null) { | |
| 695 | 695 | offset = 0; | |
| 696 | 696 | } else { | |
| 697 | - validateInteger(offset, 'offset'); | ||
| 697 | + validateInteger(offset, 'offset', 0); | ||
| 698 | 698 | } | |
| 699 | 699 | ||
| 700 | 700 | length |= 0; | |
@@ -806,7 +806,7 @@ function write(fd, buffer, offset, length, position, callback) { | |||
| 806 | 806 | if (offset == null || typeof offset === 'function') { | |
| 807 | 807 | offset = 0; | |
| 808 | 808 | } else { | |
| 809 | - validateInteger(offset, 'offset'); | ||
| 809 | + validateInteger(offset, 'offset', 0); | ||
| 810 | 810 | } | |
| 811 | 811 | if (typeof length !== 'number') | |
| 812 | 812 | length = buffer.byteLength - offset; | |
@@ -863,7 +863,7 @@ function writeSync(fd, buffer, offset, length, position) { | |||
| 863 | 863 | if (offset == null) { | |
| 864 | 864 | offset = 0; | |
| 865 | 865 | } else { | |
| 866 | - validateInteger(offset, 'offset'); | ||
| 866 | + validateInteger(offset, 'offset', 0); | ||
| 867 | 867 | } | |
| 868 | 868 | if (typeof length !== 'number') | |
| 869 | 869 | length = buffer.byteLength - offset; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -417,7 +417,7 @@ async function read(handle, bufferOrOptions, offset, length, position) { | |||
| 417 | 417 | if (offset == null) { | |
| 418 | 418 | offset = 0; | |
| 419 | 419 | } else { | |
| 420 | - validateInteger(offset, 'offset'); | ||
| 420 | + validateInteger(offset, 'offset', 0); | ||
| 421 | 421 | } | |
| 422 | 422 | ||
| 423 | 423 | length |= 0; | |
@@ -460,7 +460,7 @@ async function write(handle, buffer, offset, length, position) { | |||
| 460 | 460 | if (offset == null) { | |
| 461 | 461 | offset = 0; | |
| 462 | 462 | } else { | |
| 463 | - validateInteger(offset, 'offset'); | ||
| 463 | + validateInteger(offset, 'offset', 0); | ||
| 464 | 464 | } | |
| 465 | 465 | if (typeof length !== 'number') | |
| 466 | 466 | length = buffer.byteLength - offset; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -655,6 +655,10 @@ const validateOffsetLengthWrite = hideStackFrames( | |||
| 655 | 655 | if (length > byteLength - offset) { | |
| 656 | 656 | throw new ERR_OUT_OF_RANGE('length', `<= ${byteLength - offset}`, length); | |
| 657 | 657 | } | |
| 658 | + | ||
| 659 | + if (length < 0) { | ||
| 660 | + throw new ERR_OUT_OF_RANGE('length', '>= 0', length); | ||
| 661 | + } | ||
| 658 | 662 | } | |
| 659 | 663 | ); | |
| 660 | 664 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,8 +44,6 @@ assert.throws(() => { | |||
| 44 | 44 | }, { | |
| 45 | 45 | code: 'ERR_OUT_OF_RANGE', | |
| 46 | 46 | name: 'RangeError', | |
| 47 | - message: 'The value of "offset" is out of range. It must be >= 0. ' + | ||
| 48 | - 'Received -1' | ||
| 49 | 47 | }); | |
| 50 | 48 | ||
| 51 | 49 | assert.throws(() => { | |
@@ -157,8 +155,6 @@ assert.throws(() => { | |||
| 157 | 155 | }, { | |
| 158 | 156 | code: 'ERR_OUT_OF_RANGE', | |
| 159 | 157 | name: 'RangeError', | |
| 160 | - message: 'The value of "offset" is out of range. ' + | ||
| 161 | - 'It must be >= 0. Received -1' | ||
| 162 | 158 | }); | |
| 163 | 159 | ||
| 164 | 160 | assert.throws(() => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,55 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Tests that passing a negative offset does not crash the process | ||
| 4 | + | ||
| 5 | + const common = require('../common'); | ||
| 6 | + | ||
| 7 | + const { | ||
| 8 | + join, | ||
| 9 | + } = require('path'); | ||
| 10 | + | ||
| 11 | + const { | ||
| 12 | + closeSync, | ||
| 13 | + open, | ||
| 14 | + write, | ||
| 15 | + writeSync, | ||
| 16 | + } = require('fs'); | ||
| 17 | + | ||
| 18 | + const assert = require('assert'); | ||
| 19 | + | ||
| 20 | + const tmpdir = require('../common/tmpdir'); | ||
| 21 | + tmpdir.refresh(); | ||
| 22 | + | ||
| 23 | + const filename = join(tmpdir.path, 'test.txt'); | ||
| 24 | + | ||
| 25 | + open(filename, 'w+', common.mustSucceed((fd) => { | ||
| 26 | + assert.throws(() => { | ||
| 27 | + write(fd, Buffer.alloc(0), -1, common.mustNotCall()); | ||
| 28 | + }, { | ||
| 29 | + code: 'ERR_OUT_OF_RANGE', | ||
| 30 | + }); | ||
| 31 | + assert.throws(() => { | ||
| 32 | + writeSync(fd, Buffer.alloc(0), -1); | ||
| 33 | + }, { | ||
| 34 | + code: 'ERR_OUT_OF_RANGE', | ||
| 35 | + }); | ||
| 36 | + closeSync(fd); | ||
| 37 | + })); | ||
| 38 | + | ||
| 39 | + const filename2 = join(tmpdir.path, 'test2.txt'); | ||
| 40 | + | ||
| 41 | + // Make sure negative length's don't cause aborts either | ||
| 42 | + | ||
| 43 | + open(filename2, 'w+', common.mustSucceed((fd) => { | ||
| 44 | + assert.throws(() => { | ||
| 45 | + write(fd, Buffer.alloc(0), 0, -1, common.mustNotCall()); | ||
| 46 | + }, { | ||
| 47 | + code: 'ERR_OUT_OF_RANGE', | ||
| 48 | + }); | ||
| 49 | + assert.throws(() => { | ||
| 50 | + writeSync(fd, Buffer.alloc(0), 0, -1); | ||
| 51 | + }, { | ||
| 52 | + code: 'ERR_OUT_OF_RANGE', | ||
| 53 | + }); | ||
| 54 | + closeSync(fd); | ||
| 55 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments