Patchwork [1,of,3] pathencode: fix hashmangle short dir limit (issue3958)

login
register
mail settings
Submitter Siddharth Agarwal
Date June 20, 2013, 5:47 p.m.
Message ID <149f9a739bbecea91c11.1371750421@dev1091.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1739/
State Accepted, archived
Delegated to: Matt Mackall
Headers show

Comments

Siddharth Agarwal - June 20, 2013, 5:47 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1371706474 25200
#      Wed Jun 19 22:34:34 2013 -0700
# Node ID 149f9a739bbecea91c11fff3612909ceb3c614e0
# Parent  2c79f951df4421a628ac0a39e71aa62dccc348fe
pathencode: fix hashmangle short dir limit (issue3958)

The Python version of this (see mercurial/store.py:_hashencode) copies path
components up to a limit of maxshortdirslen bytes. The Python version does not
consider the initial "dh/" to be part of the this, though, while the C version
currently does. Adding len("dh/") == 3 to the limit for the C version brings it
in line with the Python version.

This was not caught by the randomized testing scheme in test-pathencode.py
because of a couple of flaws with the test. Upcoming patches will fix those
problems.
Siddharth Agarwal - June 21, 2013, 12:37 a.m.
On 06/20/2013 10:47 AM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1371706474 25200
> #      Wed Jun 19 22:34:34 2013 -0700
> # Node ID 149f9a739bbecea91c11fff3612909ceb3c614e0
> # Parent  2c79f951df4421a628ac0a39e71aa62dccc348fe
> pathencode: fix hashmangle short dir limit (issue3958)

This might make sense for stable, too.
Matt Mackall - June 21, 2013, 3:40 a.m.
On Thu, 2013-06-20 at 17:37 -0700, Siddharth Agarwal wrote:
> On 06/20/2013 10:47 AM, Siddharth Agarwal wrote:
> > # HG changeset patch
> > # User Siddharth Agarwal <sid0@fb.com>
> > # Date 1371706474 25200
> > #      Wed Jun 19 22:34:34 2013 -0700
> > # Node ID 149f9a739bbecea91c11fff3612909ceb3c614e0
> > # Parent  2c79f951df4421a628ac0a39e71aa62dccc348fe
> > pathencode: fix hashmangle short dir limit (issue3958)
> 
> This might make sense for stable, too.

Yes, bugfixes for issues marked critical indeed belong on stable. These
three are queued there, thanks!

Patch

diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -585,7 +585,8 @@ 
 			   in a space or dot, which are unportable. */
 			if (d == '.' || d == ' ')
 				dest[destlen - 1] = '_';
-			if (destlen > maxshortdirslen)
+			/* The + 3 is to account for "dh/" in the beginning */
+			if (destlen > maxshortdirslen + 3)
 				break;
 			charcopy(dest, &destlen, destsize, src[i]);
 			p = -1;