Patchwork D865: obsmarker: fix crash when metadata fields are >255 bytes (issue5681)

login
register
mail settings
Submitter phabricator
Date Oct. 1, 2017, 11:51 a.m.
Message ID <a65de3aa0396c0e968818aa059accf4f@localhost.localdomain>
Download mbox | patch
Permalink /patch/24325/
State Not Applicable
Headers show

Comments

phabricator - Oct. 1, 2017, 11:51 a.m.
swhitaker updated this revision to Diff 2255.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D865?vs=2229&id=2255

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

AFFECTED FILES
  mercurial/obsolete.py
  tests/test-obsolete-bounds-checking.t

CHANGE DETAILS




To: swhitaker, #hg-reviewers, ikostia
Cc: pulkit, ikostia, mercurial-devel

Patch

diff --git a/tests/test-obsolete-bounds-checking.t b/tests/test-obsolete-bounds-checking.t
new file mode 100644
--- /dev/null
+++ b/tests/test-obsolete-bounds-checking.t
@@ -0,0 +1,23 @@ 
+Create a repo, set the username to something more than 255 bytes, then run hg amend on it.
+
+  $ unset HGUSER
+  $ cat >> $HGRCPATH << EOF
+  > [ui]
+  > username = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <very.long.name@example.com>
+  > [extensions]
+  > amend =
+  > [experimental]
+  > stabilization=createmarkers,exchange
+  > EOF
+  $ hg init tmpa
+  $ cd tmpa
+  $ echo a > a
+  $ hg add
+  adding a
+  $ hg commit -m "Initial commit"
+  $ echo a >> a
+  $ hg amend 2>&1 | egrep -v '^(\*\*|  )'
+  transaction abort!
+  rollback completed
+  Traceback (most recent call last):
+  mercurial.error.ProgrammingError: obsstore metadata value cannot be longer than 255 bytes (value "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <very.long.name@example.com>" for key "user" is 285 bytes)
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -416,6 +416,14 @@ 
     for key, value in metadata:
         lk = len(key)
         lv = len(value)
+        if lk > 255:
+            msg = _('obsstore metadata key cannot be longer than 255 bytes'
+                ' (key "%s" is %u bytes)') % (key, lk)
+            raise error.ProgrammingError(msg)
+        if lv > 255:
+            msg = _('obsstore metadata value cannot be longer than 255 bytes'
+                ' (value "%s" for key "%s" is %u bytes)') % (value, key, lv)
+            raise error.ProgrammingError(msg)
         data.append(lk)
         data.append(lv)
         totalsize += lk + lv