Skip to content

Commit

Permalink
lib: add empty buffer case to read and readSync function in fs
Browse files Browse the repository at this point in the history
While using read() or readSync() function, it should be verified that
the arguments of the function are in proper range and hold legitimate
values, for a successful read process.
For this validateOffsetLengthRead() function is called, which gives an
error message for offset and length passed by the user, if not in
order. But there should also be an error when an empty buffer is passed
as argument, when it cannot be written over.
The empty buffer case should be checked before calling
validateOffsetLengthRead() and ERR_INVALID_ARG_VALUE should be thrown
corresponding to the empty buffer argument in read and readSync
function.

Fixes: nodejs#21193
  • Loading branch information
AdityaSrivast committed Jun 19, 2018
1 parent 8043755 commit a8c61fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 0 additions & 12 deletions test/fixtures/testcodes.txt

This file was deleted.

4 changes: 3 additions & 1 deletion test/parallel/test-fs-read-empty-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const fs = require('fs');
const filepath = fixtures.path('testcodes.txt');
const filepath = fixtures.path('x.txt');
const fd = fs.openSync(filepath, 'r');

const buffer = new Uint8Array();
Expand All @@ -12,5 +12,7 @@ assert.throws(
() => fs.readSync(fd, buffer, 0, 10, 0),
{
code: 'ERR_INVALID_ARG_VALUE',
message: 'The argument \'buffer\' is empty and cannot be written. ' +
'Received Uint8Array [ ]'
}
);

0 comments on commit a8c61fd

Please sign in to comment.