Skip to content

Commit

Permalink
lib: add case of bufferLength to validateOffsetLengthRead() in utils.js
Browse files Browse the repository at this point in the history
In validateOffsetLengthRead(), an error message is generated if offset
or length are out of range. There should also be an error message if
buffer is empty, in which case it cannot write data in it.

Generally this validateOffsetLengthRead() is triggered with
fs.readSync(fd, buffer, offset, length, position), where if buffer is
empty, the case for zero bufferLength is triggered and the
corresponding message is thrown.

Fixes: nodejs#21193
  • Loading branch information
AdityaSrivast committed Jun 11, 2018
1 parent e05f49c commit 7af6bb3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
2 changes: 0 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,6 @@ E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
let inspected = util.inspect(value);
if (inspected.length > 128) {
inspected = `${inspected.slice(0, 128)}...`;
} else if (inspected === '0') {
inspected = 'no value.';
}
return `The argument '${name}' ${reason}. Received ${inspected}`;
}, TypeError, RangeError);
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ function validateOffsetLengthRead(offset, length, bufferLength) {

if (offset < 0 || offset >= bufferLength) {
if (bufferLength === 0) {
throw ERR_INVALID_ARG_VALUE('buffer', 0,
'is empty and can\'t be written');
err = new ERR_OUT_OF_RANGE('bufferLength', '> 0', bufferLength);
} else {
err = new ERR_OUT_OF_RANGE('offset',
`>= 0 && <= ${bufferLength}`, offset);
Expand Down

0 comments on commit 7af6bb3

Please sign in to comment.