Skip to content

Commit a6af709

Browse files
santigimenopiscisaureus
authored andcommitted
fs: use stat.st_size only to read regular files
Using st_size to read non-regular files can lead to not reading all the data. PR-URL: #1074 Reviewed-By: Bert Belder <[email protected]>
1 parent 0782c24 commit a6af709

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/fs.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function readFileAfterStat(err, st) {
317317
if (err)
318318
return context.close(err);
319319

320-
var size = context.size = st.size;
320+
var size = context.size = st.isFile() ? st.size : 0;
321321

322322
if (size === 0) {
323323
context.buffers = [];
@@ -395,10 +395,12 @@ fs.readFileSync = function(path, options) {
395395
var flag = options.flag || 'r';
396396
var fd = fs.openSync(path, flag, 0o666);
397397

398+
var st;
398399
var size;
399400
var threw = true;
400401
try {
401-
size = fs.fstatSync(fd).size;
402+
st = fs.fstatSync(fd);
403+
size = st.isFile() ? st.size : 0;
402404
threw = false;
403405
} finally {
404406
if (threw) fs.closeSync(fd);

0 commit comments

Comments
 (0)