Patchwork D10458: nodemap: deal with data mmap error

login
register
mail settings
Submitter phabricator
Date April 16, 2021, 4:08 p.m.
Message ID <differential-rev-PHID-DREV-zqwmlpg2dei2l5repy4p-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48775/
State Superseded
Headers show

Comments

phabricator - April 16, 2021, 4:08 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If the file is too small, the mmapread call would raise a ValueError. We catch
  that and ignore nodemap content (as we do without mmap). This make the repository
  slightly slower (until the next write) but usable. Unlike the current crash.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/revlogutils/nodemap.py
  tests/test-persistent-nodemap.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -795,7 +795,11 @@ 
 
 Check that Mercurial reaction to this event
 
-  $ hg -R corruption-test-repo log -r .
-  abort: index 00changelog.i is corrupted
-  [50]
+  $ hg -R corruption-test-repo log -r . --traceback
+  changeset:   5005:90d5d3ba2fc4
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     a2
+  
 
diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -53,7 +53,11 @@ 
     try:
         with revlog.opener(filename) as fd:
             if use_mmap:
-                data = util.buffer(util.mmapread(fd, data_length))
+                try:
+                    data = util.buffer(util.mmapread(fd, data_length))
+                except ValueError:
+                    # raised when the read file is too small
+                    data = b''
             else:
                 data = fd.read(data_length)
     except (IOError, OSError) as e: