Patchwork D1394: bundle2: avoid unbound read when seeking

login
register
mail settings
Submitter phabricator
Date Nov. 20, 2017, 11:50 p.m.
Message ID <f4e6075edbf1865fb46397d632369ee3@localhost.localdomain>
Download mbox | patch
Permalink /patch/25696/
State Not Applicable
Headers show

Comments

phabricator - Nov. 20, 2017, 11:50 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG699b2a759319: bundle2: avoid unbound read when seeking (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1394?vs=3472&id=3698

REVISION DETAIL
  https://phab.mercurial-scm.org/D1394

AFFECTED FILES
  mercurial/bundle2.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1415,13 +1415,20 @@ 
             newpos = self._pos + offset
         elif whence == os.SEEK_END:
             if not self.consumed:
-                self.read()
+                # Can't use self.consume() here because it advances self._pos.
+                chunk = self.read(32768)
+                while chunk:
+                    chunk = self.read(32768)
             newpos = self._chunkindex[-1][0] - offset
         else:
             raise ValueError('Unknown whence value: %r' % (whence,))
 
         if newpos > self._chunkindex[-1][0] and not self.consumed:
-            self.read()
+            # Can't use self.consume() here because it advances self._pos.
+            chunk = self.read(32768)
+            while chunk:
+                chunk = self.read(32668)
+
         if not 0 <= newpos <= self._chunkindex[-1][0]:
             raise ValueError('Offset out of range')