Patchwork D9720: shelve: don't crash on file with unexpected extension in .hg/shelved/

login
register
mail settings
Submitter phabricator
Date Jan. 11, 2021, 6:05 p.m.
Message ID <differential-rev-PHID-DREV-j4m2m4d7qg2sfuiou6gd-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48031/
State Superseded
Headers show

Comments

phabricator - Jan. 11, 2021, 6:05 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We assumed that the files in the `.hg/shelved/` directory have an
  extension. That's a valid assumption except that users may put garbage
  in the directory. This patch fixes the crash by simply not assuming
  that the result of splittin a string at '.' yields an extension. We
  don't use the extension since the previous patch anyway.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py
  tests/test-shelve2.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -779,10 +779,10 @@ 
 
 # A file with an unexpected extension
   $ touch .hg/shelved/junk3
-  $ hg shelve -l 2>&1 | grep ValueError
-  ValueError: not enough values to unpack (expected 2, got 1)
-  $ hg unshelve 2>&1 | grep ValueError
-  ValueError: not enough values to unpack (expected 2, got 1)
+  $ hg shelve -l
+  $ hg unshelve
+  abort: no shelved changes to apply!
+  [20]
   $ hg shelve -d junk3
   abort: shelved change 'junk3' not found
   [10]
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -625,7 +625,7 @@ 
     info = []
     seen = set()
     for (filename, _type) in names:
-        name, ext = filename.rsplit(b'.', 1)
+        name = filename.rsplit(b'.', 1)[0]
         if name in seen:
             continue
         seen.add(name)