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

login
register
mail settings
Submitter phabricator
Date Jan. 15, 2020, 2:58 p.m.
Message ID <differential-rev-PHID-DREV-npxosq2vokbxnyki2z36-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44381/
State Superseded
Headers show

Comments

phabricator - Jan. 15, 2020, 2:58 p.m.
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




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

Patch

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):