mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
fs: fix infinite loop in fs.readFileSync()
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.
This commit is contained in:
parent
408bfece51
commit
0385b17ce0
@ -221,12 +221,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);
|
||||
@ -234,6 +229,8 @@ fs.readFileSync = function(path, encoding) {
|
||||
if (size === 0) {
|
||||
// data was collected into the buffers list.
|
||||
buffer = Buffer.concat(buffers, pos);
|
||||
} else if (pos < size) {
|
||||
buffer = buffer.slice(0, pos);
|
||||
}
|
||||
|
||||
if (encoding) buffer = buffer.toString(encoding);
|
||||
|
Loading…
Reference in New Issue
Block a user