Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
fs: fix infinite loop in fs.readFileSync()
Browse files Browse the repository at this point in the history
Fix an infinite loop in the case where the file got truncated by a concurrent
writer while fs.readFileSync() was busy reading in the file.
  • Loading branch information
bnoordhuis committed Jun 12, 2012
1 parent 8f1aaee commit e6c4619
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions lib/fs.js
Expand Up @@ -219,12 +219,7 @@ fs.readFileSync = function(path, encoding) {
}

pos += bytesRead;

if (size !== 0) {
done = pos >= size;
} else {
done = bytesRead >= 0;
}
done = (bytesRead === 0) || (size !== 0 && pos >= size);
}

fs.closeSync(fd);
Expand Down

0 comments on commit e6c4619

Please sign in to comment.