Patchwork D8371: manifest: fix yet another 20-byte-hash assumption

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

Comments

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

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8371?vs=20974&id=21053

BRANCH
  default

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

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

AFFECTED FILES
  mercurial/manifest.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -292,8 +292,13 @@ 
                 b"Manifest values must be a tuple of (node, flags)."
             )
         hashval = value[0]
-        if not isinstance(hashval, bytes) or not 20 <= len(hashval) <= 22:
-            raise TypeError(b"node must be a 20-byte byte string")
+        # hashes are either 20 or 32 bytes (sha1 or its replacement),
+        # and allow one extra byte taht won't be persisted to disk but
+        # is sometimes used in memory.
+        if not isinstance(hashval, bytes) or not (
+            20 <= len(hashval) <= 22 or 32 <= len(hashval) <= 34
+        ):
+            raise TypeError(b"node must be a 20-byte or 32-byte byte string")
         flags = value[1]
         if len(hashval) == 22:
             hashval = hashval[:-1]