Patchwork D8370: manifest: fix another pure-parsing 20-byte assumption

login
register
mail settings
Submitter phabricator
Date April 14, 2020, 3:29 p.m.
Message ID <8fae4a0f2d3d6d18c1ae7c01dadcc7fe@localhost.localdomain>
Download mbox | patch
Permalink /patch/46080/
State Not Applicable
Headers show

Comments

phabricator - April 14, 2020, 3:29 p.m.
durin42 updated this revision to Diff 21052.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8370?vs=20973&id=21052

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8370/new/

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

AFFECTED FILES
  mercurial/manifest.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -377,8 +377,13 @@ 
                     t = self.extradata[-cur - 1]
                     l.append(self._pack(t))
                     self.positions[i] = offset
-                    if len(t[1]) > 20:
-                        self.extrainfo[i] = ord(t[1][21])
+                    # Hashes are either 20 bytes (old sha1s) or 32
+                    # bytes (new non-sha1).
+                    hlen = 20
+                    if len(t[1]) > 25:
+                        hlen = 32
+                    if len(t[1]) > hlen:
+                        self.extrainfo[i] = ord(t[1][hlen + 1])
                     offset += len(l[-1])
                     i += 1
         self.data = b''.join(l)