Patchwork D8372: manifest: remove a final 40-byte assumption from pure-python parser

login
register
mail settings
Submitter phabricator
Date April 2, 2020, 8:32 p.m.
Message ID <differential-rev-PHID-DREV-cmouyyytqhtfcwlc7kg6-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46007/
State Superseded
Headers show

Comments

phabricator - April 2, 2020, 8:32 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/manifest.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - April 15, 2020, 11:03 a.m.
> diff --git a/mercurial/manifest.py b/mercurial/manifest.py
> --- a/mercurial/manifest.py
> +++ b/mercurial/manifest.py
> @@ -57,7 +57,10 @@
>              raise ValueError(b'Manifest lines not in sorted order.')
>          prev = l
>          f, n = l.split(b'\0')
> -        if len(n) > 40:
> +        nl = len(n)
> +        if 64 < nl:
> +            yield f, bin(n[:64]), n[64:]
> +        if 40 < nl < 45:
>              yield f, bin(n[:40]), n[40:]
>          else:
>              yield f, bin(n), b''

`elif 40 < nl:`

otherwise full-width hash would be yielded twice.
phabricator - April 15, 2020, 11:05 a.m.
yuja added a comment.


  > diff --git a/mercurial/manifest.py b/mercurial/manifest.py
  >
  > - a/mercurial/manifest.py
  >
  > +++ b/mercurial/manifest.py
  > @@ -57,7 +57,10 @@
  >
  >       raise ValueError(b'Manifest lines not in sorted order.')
  >   prev = l
  >   f, n = l.split(b'\0')
  >
  > - if len(n) > 40:
  >
  > +        nl = len(n)
  > +        if 64 < nl:
  > +            yield f, bin(n[:64]), n[64:]
  > +        if 40 < nl < 45:
  >
  >       yield f, bin(n[:40]), n[40:]
  >   else:
  >       yield f, bin(n), b''
  
  `elif 40 < nl:`
  
  otherwise full-width hash would be yielded twice.

REPOSITORY
  rHG Mercurial

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

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

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

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -57,7 +57,10 @@ 
             raise ValueError(b'Manifest lines not in sorted order.')
         prev = l
         f, n = l.split(b'\0')
-        if len(n) > 40:
+        nl = len(n)
+        if 64 < nl:
+            yield f, bin(n[:64]), n[64:]
+        if 40 < nl < 45:
             yield f, bin(n[:40]), n[40:]
         else:
             yield f, bin(n), b''
@@ -265,9 +268,13 @@ 
         if pos == -1:
             return (data[1], data[2])
         zeropos = data.find(b'\x00', pos)
+        nlpos = data.find(b'\n', zeropos)
         assert 0 <= needle <= len(self.positions)
         assert len(self.extrainfo) == len(self.positions)
-        hashval = unhexlify(data, self.extrainfo[needle], zeropos + 1, 40)
+        hlen = nlpos - zeropos - 1
+        if hlen % 2:
+            hlen -= 1
+        hashval = unhexlify(data, self.extrainfo[needle], zeropos + 1, hlen)
         flags = self._getflags(data, needle, zeropos)
         return (hashval, flags)