D7892: nodemap: never read more than the expected data amount

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Wed Jan 15 14:58:27 UTC 2020


marmoute created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Since we are tracking this number we can use it to detect corrupted rawdata file
  and to only read the correct amount of data when possible.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/revlogutils/nodemap.py

CHANGE DETAILS

diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -45,7 +45,12 @@
     docket.data_unused = data_unused
 
     filename = _rawdata_filepath(revlog, docket)
-    return docket, revlog.opener.tryread(filename)
+    data = revlog.opener.tryread(filename)
+    if len(data) < data_length:
+        return None
+    elif len(data) > data_length:
+        data = data[:data_length]
+    return docket, data
 
 
 def setup_persistent_nodemap(tr, revlog):



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


More information about the Mercurial-devel mailing list