From a6af70948924625566c48bfb381ce7a804f98520 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Thu, 5 Mar 2015 18:33:38 +0100 Subject: [PATCH] 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: https://github.com/iojs/io.js/pull/1074 Reviewed-By: Bert Belder --- lib/fs.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 9828b3099c..adcb708021 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -317,7 +317,7 @@ function readFileAfterStat(err, st) { if (err) return context.close(err); - var size = context.size = st.size; + var size = context.size = st.isFile() ? st.size : 0; if (size === 0) { context.buffers = []; @@ -395,10 +395,12 @@ fs.readFileSync = function(path, options) { var flag = options.flag || 'r'; var fd = fs.openSync(path, flag, 0o666); + var st; var size; var threw = true; try { - size = fs.fstatSync(fd).size; + st = fs.fstatSync(fd); + size = st.isFile() ? st.size : 0; threw = false; } finally { if (threw) fs.closeSync(fd);