summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Murty <james@murty.co>2014-05-29 09:39:13 +0100
committerJames Murty <james@murty.co>2014-05-29 09:39:13 +0100
commit697b834d6be85196d6ecd29708f8265628a015de (patch)
tree410527ded5d0d4eeae8d3ca073c3d7aef013e2c5
parentc061c140f9bb4959a80692b8bf044c2f75610781 (diff)
downloadgit-fat-697b834d6be85196d6ecd29708f8265628a015de.tar.gz
Avoid potential infinite loop if unexpected EOF received from cat-file
Use read() method more defensively to avoid any chance of an infinite loop in the (very unlikely) event an EOF is received mid-way through some `cat-file` data.
-rwxr-xr-xgit-fat15
1 files changed, 11 insertions, 4 deletions
diff --git a/git-fat b/git-fat
index bb01580..7eaef13 100755
--- a/git-fat
+++ b/git-fat
@@ -319,16 +319,23 @@ class GitFat(object):
# is small enough to read into memory and process
content = ''
while bytes_read < size:
- content += p3.stdout.read(size - bytes_read)
- bytes_read = len(content)
+ data = p3.stdout.read(size - bytes_read)
+ if not data:
+ break # EOF
+ content += data
+ bytes_read += len(data)
try:
fathash = self.decode(content)[0]
referenced.add(fathash)
except GitFat.DecodeError:
pass
# Consume LF record delimiter in `cat-file --batch` output
- while not p3.stdout.read(1):
- pass
+ bytes_read = 0
+ while bytes_read < 1:
+ data = p3.stdout.read(1)
+ if not data:
+ break # EOF
+ bytes_read += len(data)
# Ensure everything is cleaned up
cut_thread.join()
filter_thread.join()