Patchwork D5266: revlog: detect incomplete revlog reads

login
register
mail settings
Submitter phabricator
Date Nov. 14, 2018, 12:29 p.m.
Message ID <e1529bf0eff771fcd5cc510a87689073@localhost.localdomain>
Download mbox | patch
Permalink /patch/36567/
State Not Applicable
Headers show

Comments

phabricator - Nov. 14, 2018, 12:29 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG87a872555e90: revlog: detect incomplete revlog reads (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5266?vs=12528&id=12533

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

AFFECTED FILES
  mercurial/revlog.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1342,6 +1342,8 @@ 
         original seek position will NOT be restored.
 
         Returns a str or buffer of raw byte data.
+
+        Raises if the requested number of bytes could not be read.
         """
         # Cache data both forward and backward around the requested
         # data, in a fixed size window. This helps speed up operations
@@ -1353,9 +1355,26 @@ 
         with self._datareadfp(df) as df:
             df.seek(realoffset)
             d = df.read(reallength)
+
         self._cachesegment(realoffset, d)
         if offset != realoffset or reallength != length:
-            return util.buffer(d, offset - realoffset, length)
+            startoffset = offset - realoffset
+            if len(d) - startoffset < length:
+                raise error.RevlogError(
+                    _('partial read of revlog %s; expected %d bytes from '
+                      'offset %d, got %d') %
+                    (self.indexfile if self._inline else self.datafile,
+                     length, realoffset, len(d) - startoffset))
+
+            return util.buffer(d, startoffset, length)
+
+        if len(d) < length:
+            raise error.RevlogError(
+                _('partial read of revlog %s; expected %d bytes from offset '
+                  '%d, got %d') %
+                (self.indexfile if self._inline else self.datafile,
+                 length, offset, len(d)))
+
         return d
 
     def _getsegment(self, offset, length, df=None):