From 697b834d6be85196d6ecd29708f8265628a015de Mon Sep 17 00:00:00 2001 From: James Murty Date: Thu, 29 May 2014 09:39:13 +0100 Subject: 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. --- git-fat | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'git-fat') 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() -- cgit v1.2.1