comparison mercurial/util.py @ 43494:5d40317d42b7

dirs: reject consecutive slashes in paths We shouldn't ever see those, and the fuzzer go really excited that if it gives us a 65k string with 55k slashes in it we use a lot of RAM. This is a better fix than what I tried in D7105. It was suggested by Yuya, and I verified it does in fact cause the fuzzer to not OOM. This is a revision of D7234, but with the missing set of an error added. I added a unit test of the dirs behavior because I needed to reason more carefully about the failure modes around consecutive slashes. Differential Revision: https://phab.mercurial-scm.org/D7252
author Augie Fackler <augie@google.com>
date Thu, 17 Oct 2019 19:29:22 -0400
parents 70d42e2ad9b4
children 9f70512ae2cf
comparison
equal deleted inserted replaced
43493:3a463e5e470b 43494:5d40317d42b7
3513 addpath(f) 3513 addpath(f)
3514 3514
3515 def addpath(self, path): 3515 def addpath(self, path):
3516 dirs = self._dirs 3516 dirs = self._dirs
3517 for base in finddirs(path): 3517 for base in finddirs(path):
3518 if base.endswith(b'/'):
3519 raise ValueError(
3520 "found invalid consecutive slashes in path: %r" % base
3521 )
3518 if base in dirs: 3522 if base in dirs:
3519 dirs[base] += 1 3523 dirs[base] += 1
3520 return 3524 return
3521 dirs[base] = 1 3525 dirs[base] = 1
3522 3526