changeset 39209:1af95139e5ec

util: improve handling of truncated compressed streams If the compressed stream is over as marked by the reader providing nothing new and the compression engine is not providing data, bail out. This can happen in practise when the server misbehaves and would result in an infinite loop otherwise. Differential Revision: https://phab.mercurial-scm.org/D4297
author Joerg Sonnenberger <joerg@bec.de>
date Thu, 16 Aug 2018 05:50:49 +0200
parents 362c4603602d
children 1ddb296e0dee
files mercurial/util.py
diffstat 1 files changed, 3 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Fri Aug 10 23:24:33 2018 +0800
+++ b/mercurial/util.py	Thu Aug 16 05:50:49 2018 +0200
@@ -3377,6 +3377,9 @@
                 return ''.join(buf)
             chunk = self._reader(65536)
             self._decompress(chunk)
+            if not chunk and not self._pending and not self._eof:
+                # No progress and no new data, bail out
+                return ''.join(buf)
 
 class _GzipCompressedStreamReader(_CompressedStreamReader):
     def __init__(self, fh):