changeset 44373:c7eebdb15139

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
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Jan 2020 15:50:52 +0100
parents 2ea6a67ff502
children 6ecc34b31137
files mercurial/revlogutils/nodemap.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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):