nodemap: never read more than the expected data amount
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 15 Jan 2020 15:50:52 +0100
changeset 44339 c7eebdb15139
parent 44338 2ea6a67ff502
child 44340 6ecc34b31137
nodemap: never read more than the expected data amount 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. Differential Revision: https://phab.mercurial-scm.org/D7892
mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py	Wed Jan 15 15:50:43 2020 +0100
+++ b/mercurial/revlogutils/nodemap.py	Wed Jan 15 15:50:52 2020 +0100
@@ -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):