[PATCH 3 of 4] revlog: raise an exception earlier if an entry is too large

Jordi GutiƩrrez Hermoso jordigh at octave.org
Thu May 21 15:30:21 CDT 2015


# HG changeset patch
# User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
# Date 1432239712 14400
#      Thu May 21 16:21:52 2015 -0400
# Node ID 94b79351d9569b65c3c111cbfe88a03112d617a9
# Parent  88b99c48761cc7b982b84294aa679b63f5edf967
revlog: raise an exception earlier if an entry is too large

Before we were relying on _pack to error out when trying to pass an
integer that was too large for the "i" format specifier. Now we check
this earlier so we can form a better error message.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -152,6 +152,10 @@ indexformatng = ">Qiiiiii20s12x"
 ngshaoffset = 32
 versionformat = ">I"
 
+# matches uncompressed length of indexformatng (2 gigs, 4-byte signed
+# integer)
+maxentrysize = 2147483648
+
 class revlogio(object):
     def __init__(self):
         self.size = struct.calcsize(indexformatng)
@@ -162,6 +166,11 @@ class revlogio(object):
         return index, getattr(index, 'nodemap', None), cache
 
     def packentry(self, entry, node, version, rev):
+        # uncompressed length
+        if entry[2] > maxentrysize:
+            raise RevlogError(_("too large for revlog storage"),
+                              hint=_("consider using the largefiles extension"))
+
         p = _pack(indexformatng, *entry)
         if rev == 0:
             p = _pack(versionformat, version) + p[4:]


More information about the Mercurial-devel mailing list