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

Matt Mackall mpm at selenic.com
Fri May 22 12:05:02 CDT 2015


On Thu, 2015-05-21 at 16:30 -0400, Jordi GutiƩrrez Hermoso wrote:
> # 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

Issue number?

> 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
> +

You're off by one. The limit is 0x7fffffff. Let's use hex, add a
comment, and prefix with _.

>  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"),

Should mention 2G. And probably the filename.

> +                              hint=_("consider using the largefiles extension"))

Eek. I'm not sure about that. Can we get just the fix and then bikeshed
the hint part?

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list