Patchwork [v2] revlog: ensure that flags do not overflow 2 bytes

login
register
mail settings
Submitter Cotizo Sima
Date Nov. 28, 2016, 12:43 p.m.
Message ID <bfbb27dffad7ae41e523.1480337021@devvm800.lla2.facebook.com>
Download mbox | patch
Permalink /patch/17768/
State Accepted
Headers show

Comments

Cotizo Sima - Nov. 28, 2016, 12:43 p.m.
# HG changeset patch
# User Cotizo Sima <cotizo@fb.com>
# Date 1480336441 28800
#      Mon Nov 28 04:34:01 2016 -0800
# Node ID bfbb27dffad7ae41e5238087b4e7ff5a26b030b5
# Parent  a3163433647108b7bec8fc45896db1c20b18ab21
revlog: ensure that flags do not overflow 2 bytes

This patch adds a line that ensures we are not setting by mistake a set of flags
overlfowing the 2 bytes they are allocated. Given the way the data is packed in
the revlog header, overflowing 2 bytes will result in setting a wrong offset.
Yuya Nishihara - Nov. 29, 2016, 1:17 p.m.
On Mon, 28 Nov 2016 04:43:41 -0800, Cotizo Sima wrote:
> # HG changeset patch
> # User Cotizo Sima <cotizo@fb.com>
> # Date 1480336441 28800
> #      Mon Nov 28 04:34:01 2016 -0800
> # Node ID bfbb27dffad7ae41e5238087b4e7ff5a26b030b5
> # Parent  a3163433647108b7bec8fc45896db1c20b18ab21
> revlog: ensure that flags do not overflow 2 bytes

Queued, thanks.

> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -72,6 +72,8 @@
>      return int(q & 0xFFFF)
>  
>  def offset_type(offset, type):
> +    if (type & ~REVIDX_KNOWN_FLAGS) != 0:
> +        raise ValueError(_('unknown revlog index flags'))

I've dropped _() since it is the check for developers.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -72,6 +72,8 @@ 
     return int(q & 0xFFFF)
 
 def offset_type(offset, type):
+    if (type & ~REVIDX_KNOWN_FLAGS) != 0:
+        raise ValueError(_('unknown revlog index flags'))
     return long(long(offset) << 16 | type)
 
 _nullhash = hashlib.sha1(nullid)