Version in base suite: 7.0.1-2 Base version: mercurial_7.0.1-2 Target version: mercurial_7.0.1-2+deb13u1 Base file: /srv/ftp-master.debian.org/ftp/pool/main/m/mercurial/mercurial_7.0.1-2.dsc Target file: /srv/ftp-master.debian.org/policy/pool/main/m/mercurial/mercurial_7.0.1-2+deb13u1.dsc /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/base-bundle.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-bundle.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-compzstd.tar |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-general-delta.tar |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-prev-delta.tar |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-sparse-delta.tar |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-storeless.tar |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-compzstd.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-general-delta.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-prev-delta.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-sparse-delta.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-storeless.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-compzstd.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-general-delta.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-prev-delta.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-sparse-delta.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-storeless.hg |binary /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/tampered.tar |binary mercurial-7.0.1/debian/changelog | 15 mercurial-7.0.1/debian/control | 3 mercurial-7.0.1/debian/patches/deb_specific__system-zstandard.patch | 29 mercurial-7.0.1/debian/patches/hg-sa-2026-001.patch | 2315 ++++++++++ mercurial-7.0.1/debian/patches/hg-sa-2026-003.patch | 95 mercurial-7.0.1/debian/patches/hg-sa-2026-004.patch | 567 ++ mercurial-7.0.1/debian/patches/series | 6 mercurial-7.0.1/debian/patches/test-hghave-zstd.patch | 29 mercurial-7.0.1/debian/patches/zstd-policy.patch | 229 mercurial-7.0.1/debian/rules | 7 mercurial-7.0.1/debian/source/include-binaries | 18 29 files changed, 3312 insertions(+), 1 deletion(-) dpkg-source: warning: cannot verify inline signature for /srv/release.debian.org/tmp/tmpjmk5bw0h/mercurial_7.0.1-2.dsc: no acceptable signature found dpkg-source: warning: cannot verify inline signature for /srv/release.debian.org/tmp/tmpjmk5bw0h/mercurial_7.0.1-2+deb13u1.dsc: no acceptable signature found diff -Nru mercurial-7.0.1/debian/changelog mercurial-7.0.1/debian/changelog --- mercurial-7.0.1/debian/changelog 2025-04-28 16:43:34.000000000 +0000 +++ mercurial-7.0.1/debian/changelog 2026-12-02 17:25:42.000000000 +0000 @@ -1,3 +1,18 @@ +mercurial (7.0.1-2+deb13u1) trixie-security; urgency=high + + * Use python3-zstandard instead of a vendored copy. + * HG-SA-2026-001: refuse to write forbidden paths such as .hg/hgrc from + hg archive, unbundle, pull/push, stream clones and local clones, and + prevent archives from writing through symlinks when unpacked. + * HG-SA-2026-003: write symlinks before regular files, deepest first, + when updating the working copy, so that parallel workers cannot race to + write a file through a symlink, e.g. into .hg/hgrc. + * HG-SA-2026-004: refuse line breaks in subrepository sources from .hgsub + and in the default path written by hg clone and hg share, which allowed + injecting configuration into .hg/hgrc and running arbitrary code. + + -- Julien Cristau Wed, 02 Dec 2026 18:25:42 +0100 + mercurial (7.0.1-2) unstable; urgency=high [ Bo YU ] diff -Nru mercurial-7.0.1/debian/control mercurial-7.0.1/debian/control --- mercurial-7.0.1/debian/control 2025-04-18 15:28:42.000000000 +0000 +++ mercurial-7.0.1/debian/control 2026-12-01 08:30:28.000000000 +0000 @@ -18,6 +18,7 @@ python3-roman, python3-packaging , python3-venv , + python3-zstandard , rename , unzip , zip , @@ -30,7 +31,7 @@ Package: mercurial-common Architecture: all -Depends: ${misc:Depends}, ${python3:Depends} +Depends: python3-zstandard, ${misc:Depends}, ${python3:Depends} Recommends: ca-certificates, mercurial (>= ${source:Version}), sensible-utils Suggests: python3-mysqldb, python3-openssl, python3-pygments, wish Breaks: mercurial (<< ${source:Version}) diff -Nru mercurial-7.0.1/debian/patches/deb_specific__system-zstandard.patch mercurial-7.0.1/debian/patches/deb_specific__system-zstandard.patch --- mercurial-7.0.1/debian/patches/deb_specific__system-zstandard.patch 1970-01-01 00:00:00.000000000 +0000 +++ mercurial-7.0.1/debian/patches/deb_specific__system-zstandard.patch 2026-12-01 08:30:24.000000000 +0000 @@ -0,0 +1,29 @@ +From: Julien Cristau +Subject: Don't build the vendored zstd module + +Use the system python3-zstandard package instead of building +mercurial.zstd from contrib/python-zstandard, which embeds a copy of +libzstd. mercurial.policy already falls back to "import zstandard" when +mercurial.zstd is not available. + +Forwarded: not-needed +--- +--- a/setup.py ++++ b/setup.py +@@ -1297,14 +1297,8 @@ if os.name != 'nt': + ), + ] + +-sys.path.insert(0, 'contrib/python-zstandard') +-import setup_zstd +- +-zstd = setup_zstd.get_c_extension( +- name='mercurial.zstd', root=os.path.abspath(os.path.dirname(__file__)) +-) +-zstd.extra_compile_args += common_cflags +-extmodules.append(zstd) ++# Debian: don't build the vendored python-zstandard (and its embedded copy ++# of libzstd); mercurial.policy falls back to the system zstandard module. + + try: + from distutils import cygwinccompiler diff -Nru mercurial-7.0.1/debian/patches/hg-sa-2026-001.patch mercurial-7.0.1/debian/patches/hg-sa-2026-001.patch --- mercurial-7.0.1/debian/patches/hg-sa-2026-001.patch 1970-01-01 00:00:00.000000000 +0000 +++ mercurial-7.0.1/debian/patches/hg-sa-2026-001.patch 2026-12-02 16:32:15.000000000 +0000 @@ -0,0 +1,2315 @@ +# HG changeset patch +# User Raphaël Gomès +# Date 1796224275 -3600 +# Wed Dec 02 16:11:15 2026 +0100 +# Branch stable +# Node ID b155049a2214488106c40f491db7ec3b050dedb3 +# Parent 98f3571f3f4485949b140ffe450ee288b743d2bb +# EXP-Topic hg-sa-2026-001-7.0 +hg-sa-2026-001: backport the fixes to Mercurial 7.0 + +A changeset can record files that Mercurial must never write, such as +`.hg/hgrc`. Updating the working copy already refuses them, but other commands +did not: `hg archive` produced archives holding a repository with a malicious +hgrc, ready to run code on the next `hg` command run in them, and unbundling, +stream clones and local clones propagated such changesets silently. Archives +could also hold a symlink and a file below it, which unpacking wrote through +the symlink. + +This patch applies on top of Mercurial 7.0.3 (a9b453aa7524). It is the +difference between the head of the 7.0 line (98f3571f3f44) and 77937b7871da, +which merges the HG-SA-2026-001 fixes into it. It bundles: + +- `hg archive` audits every exported path, explicitly creates every directory + in tar and zip archives, and adds symlinks last, deepest first, so that + unpacking an archive cannot write through a symlink; +- filelogs with a forbidden name can no longer be opened or created, which + makes unbundling, and thus pull and push, refuse such changesets; +- stream clones refuse to send or receive such filelogs, in both the v1 and + v2 formats, and local clones refuse to copy them; +- static-http repositories audit store paths like other repositories, and + proxy vfs forward `audit` (grafts of b5500857e173 and 9c38e9e881de); +- `hg log` and the `filelog()` revset skip the empty file name instead of + opening a filelog for it; +- the tests showing each attack vector, with the evil repositories and + bundles they use, and the updates of existing tests: archives now list + their directories, and `test-audit-path.t` and `test-commit.t` no longer + rely on creating forbidden files. + +The binary test bundles under tests/bundles/ were removed from this patch +for dpkg-source: they are shipped in debian/tests-bundles/ and copied into +tests/bundles/ by debian/rules before running the tests. + +diff --git a/mercurial/archival.py b/mercurial/archival.py +--- a/mercurial/archival.py ++++ b/mercurial/archival.py +@@ -43,6 +43,7 @@ if typing.TYPE_CHECKING: + stringio = util.stringio + + # from unzip source code: ++_UNX_IFDIR = 0x4000 + _UNX_IFREG = 0x8000 + _UNX_IFLNK = 0xA000 + +@@ -149,6 +150,7 @@ class tarit: + def __init__(self, dest, mtime, kind: str = ''): + self.mtime = mtime + self.fileobj = None ++ self._seen_dirs = set() + + def taropen( + mode: str, name: bytes = b'', fileobj=None +@@ -177,7 +179,29 @@ class tarit: + else: + self.z = taropen('w|', fileobj=dest) + ++ def _ensure_dir(self, dir_name): ++ """make sure a directory is explicitly created for this path ++ ++ Explicitly creating directory prevent the use of "write-through ++ symlink" attack with the generated archive as the creation of the ++ directoy will clash with the creation of the symlink.V ++ """ ++ assert not dir_name.endswith(b'/') ++ if not dir_name: ++ return # no need to create the root directory ++ if dir_name not in self._seen_dirs: ++ parent_dir = os.path.dirname(dir_name) ++ self._ensure_dir(parent_dir) ++ name = pycompat.fsdecode(dir_name + b'/') ++ i = tarfile.TarInfo(name) ++ i.type = tarfile.DIRTYPE ++ i.mode = 0o755 ++ self.z.addfile(i) ++ self._seen_dirs.add(dir_name) ++ + def addfile(self, name, mode, islink, data): ++ parent_dir = os.path.dirname(name) ++ self._ensure_dir(parent_dir) + name = pycompat.fsdecode(name) + i = tarfile.TarInfo(name) + i.mtime = self.mtime +@@ -218,8 +242,49 @@ class zipit: + + self.mtime = mtime + self.date_time = time.gmtime(mtime)[:6] ++ self._seen_dirs = set() ++ ++ def _ensure_dir(self, dir_name): ++ """make sure a directory is explicitly created for this path ++ ++ Explicitly creating directory prevent the use of "write-through ++ symlink" attack with the generated archive as the creation of the ++ directoy will clash with the creation of the symlink.V ++ """ ++ assert not dir_name.endswith(b'/') ++ if not dir_name: ++ return # no need to create the root directory ++ if dir_name not in self._seen_dirs: ++ parent_dir = os.path.dirname(dir_name) ++ self._ensure_dir(parent_dir) ++ name = pycompat.fsdecode(dir_name + b'/') ++ i = zipfile.ZipInfo(name, self.date_time) ++ assert i.is_dir() ++ i.compress_type = ( ++ self.z.compression ++ ) # pytype: disable=attribute-error ++ # unzip will not honor unix file modes unless file creator is ++ # set to unix (id 3). ++ i.create_system = 3 ++ ftype = _UNX_IFDIR ++ mode = 0o755 ++ i.external_attr = (mode | ftype) << 16 ++ # add "extended-timestamp" extra block, because zip archives ++ # without this will be extracted with unexpected timestamp, ++ # if TZ is not configured as GMT ++ i.extra += struct.pack( ++ b' bool: + def _walkstreamfiles( + repo, matcher=None, phase: bool = False, obsolescence: bool = False + ): +- return repo.store.walk(matcher, phase=phase, obsolescence=obsolescence) ++ for e in repo.store.walk(matcher, phase=phase, obsolescence=obsolescence): ++ if e.is_revlog and e.is_filelog: ++ repo.svfs.audit(e.target_id) ++ yield e + + + def _report_transferred( +@@ -510,6 +513,9 @@ def consumev1(repo, fp, filecount: int, + ) + # for backwards compat, name was partially encoded + path = store.decodedir(name) ++ filename = store.parse_filelog_radix(path) ++ if filename is not None: ++ repo.svfs.audit(filename) + with repo.svfs(path, b'w', backgroundclose=True) as ofp: + total_file_count += 1 + for chunk in util.filechunkiter(fp, limit=size): +@@ -1527,6 +1533,9 @@ def _v2_parse_files( + b'adding [%s] %s (%s)\n' % (src, name, util.bytecount(datalen)) + ) + vfs = vfs_map[src] ++ filename = store.parse_filelog_radix(name) ++ if filename is not None and src == _srcstore: ++ vfs.audit(filename) + path, mode = vfs.prepare_streamed_file(name, known_dirs) + if datalen <= util.DEFAULT_FILE_CHUNK: + c = fp.read(datalen) +@@ -1620,6 +1629,9 @@ def consumev3(repo, fp) -> None: + msg = b'adding [%s] %s (%s)\n' + msg %= (src, name, util.bytecount(datalen)) + repo.ui.debug(msg) ++ filename = store.parse_filelog_radix(name) ++ if filename is not None and src == _srcstore: ++ vfs.audit(filename) + bytes_transferred += datalen + + with vfs(name, b'w') as ofp: +@@ -1700,6 +1712,9 @@ def _copy_files(src_vfs_map, dst_vfs_map + dirname = os.path.dirname(dst_path) + if not os.path.exists(dirname): + util.makedirs(dirname) ++ filename = store.parse_filelog_radix(path) ++ if filename is not None and k == _srcstore: ++ dst_vfs.audit(filename) + dst_vfs.register_file(path) + # XXX we could use the #nb_bytes argument. + try: +diff --git a/mercurial/vfs.py b/mercurial/vfs.py +--- a/mercurial/vfs.py ++++ b/mercurial/vfs.py +@@ -750,6 +750,10 @@ class proxyvfs(abstractvfs, abc.ABC): + def audit(self): + return self.vfs.audit + ++ @audit.setter ++ def audit(self, audit): ++ self.vfs.audit = audit ++ + + class filtervfs(proxyvfs, abstractvfs): + '''Wrapper vfs for filtering filenames with a function.''' +diff --git a/tests/bundles/rc-variants/compzstd.rc b/tests/bundles/rc-variants/compzstd.rc +new file mode 100644 +--- /dev/null ++++ b/tests/bundles/rc-variants/compzstd.rc +@@ -0,0 +1,12 @@ ++[format] ++usestore=yes ++usefncache=yes ++usegeneraldelta=yes ++sparse-revlog=yes ++revlog-compression=zstd ++use-share-safe=no ++use-dirstate-tracked-hint=no ++use-persistent-nodemap=no ++use-dirstate-v2=no ++use-delta-info-flags=no ++use-fileindex-v1=no +diff --git a/tests/bundles/rc-variants/general-delta.rc b/tests/bundles/rc-variants/general-delta.rc +new file mode 100644 +--- /dev/null ++++ b/tests/bundles/rc-variants/general-delta.rc +@@ -0,0 +1,12 @@ ++[format] ++usestore=yes ++usefncache=yes ++usegeneraldelta=yes ++sparse-revlog=no ++revlog-compression=zlib ++use-share-safe=no ++use-dirstate-tracked-hint=no ++use-persistent-nodemap=no ++use-dirstate-v2=no ++use-delta-info-flags=no ++use-fileindex-v1=no +diff --git a/tests/bundles/rc-variants/prev-delta.rc b/tests/bundles/rc-variants/prev-delta.rc +new file mode 100644 +--- /dev/null ++++ b/tests/bundles/rc-variants/prev-delta.rc +@@ -0,0 +1,12 @@ ++[format] ++usestore=yes ++usefncache=yes ++usegeneraldelta=no ++sparse-revlog=no ++revlog-compression=zlib ++use-share-safe=no ++use-dirstate-tracked-hint=no ++use-persistent-nodemap=no ++use-dirstate-v2=no ++use-delta-info-flags=no ++use-fileindex-v1=no +diff --git a/tests/bundles/rc-variants/sparse-delta.rc b/tests/bundles/rc-variants/sparse-delta.rc +new file mode 100644 +--- /dev/null ++++ b/tests/bundles/rc-variants/sparse-delta.rc +@@ -0,0 +1,12 @@ ++[format] ++usestore=yes ++usefncache=yes ++usegeneraldelta=yes ++sparse-revlog=yes ++revlog-compression=zlib ++use-share-safe=no ++use-dirstate-tracked-hint=no ++use-persistent-nodemap=no ++use-dirstate-v2=no ++use-delta-info-flags=no ++use-fileindex-v1=no +diff --git a/tests/bundles/rc-variants/storeless.rc b/tests/bundles/rc-variants/storeless.rc +new file mode 100644 +--- /dev/null ++++ b/tests/bundles/rc-variants/storeless.rc +@@ -0,0 +1,12 @@ ++[format] ++usestore=no ++usefncache=no ++usegeneraldelta=no ++sparse-revlog=no ++revlog-compression=zlib ++use-share-safe=no ++use-dirstate-tracked-hint=no ++use-persistent-nodemap=no ++use-dirstate-v2=no ++use-delta-info-flags=no ++use-fileindex-v1=no +diff --git a/tests/f b/tests/f +--- a/tests/f ++++ b/tests/f +@@ -25,7 +25,6 @@ This can be used instead of tools like: + + + import binascii +-import glob + import hashlib + import optparse + import os +@@ -78,7 +77,9 @@ def visit(opts, filenames, outfile): + facts.append(b'size=%d' % len(content)) + elif isdir: + if opts.recurse or opts.type: +- dirfiles = glob.glob(f + '/*') ++ # not `glob.glob`: listing hidden files with it needs the ++ # `include_hidden` argument, that only exists since Python 3.11 ++ dirfiles = [f + '/' + name for name in os.listdir(f)] + facts.append(b'directory with %d files' % len(dirfiles)) + elif opts.type: + facts.append(b'type unknown') +diff --git a/tests/test-archive.t b/tests/test-archive.t +--- a/tests/test-archive.t ++++ b/tests/test-archive.t +@@ -132,7 +132,7 @@ check http return codes + transfer-encoding: chunked + + body: size=506, sha1=70926a04cb8887d0bcccf5380488100a10222def (py38 no-py39 !) +- body: size=505, sha1=eb823c293bedff0df4070b854e2c5cbb06d6ec62 (py39 !) ++ body: size=553, sha1=d5ac805b760ba754e26f29447da49798d10aba59 + % tar.bz2 and zip disallowed should both give 403 + 403 Archive type not allowed + content-type: text/html; charset=ascii +@@ -161,7 +161,7 @@ check http return codes + transfer-encoding: chunked + + body: size=506, sha1=1bd1f8e8d3701704bd4385038bd9c09b81c77f4e (py38 no-py39 !) +- body: size=503, sha1=2d8ce8bb3816603b9683a1804a5a02c11224cb01 (py39 !) ++ body: size=545, sha1=2e96ec202aec6122f60d048e05d21cc17500746c (py39 !) + % zip and tar.gz disallowed should both give 403 + 403 Archive type not allowed + content-type: text/html; charset=ascii +@@ -189,7 +189,7 @@ check http return codes + server: testing stub value + transfer-encoding: chunked + +- body: size=(1377|1461|1489), sha1=(677b14d3d048778d5eb5552c14a67e6192068650|be6d3983aa13dfe930361b2569291cdedd02b537|1897e496871aa89ad685a92b936f5fa0d008b9e8) (re) ++ body: size=2005, sha1=9d3ba755e98726859058ef606997e4e7d35886cc + % tar.gz and tar.bz2 disallowed should both give 403 + 403 Archive type not allowed + content-type: text/html; charset=ascii +@@ -221,7 +221,7 @@ check http return codes (with deprecated + transfer-encoding: chunked + + body: size=506, sha1=70926a04cb8887d0bcccf5380488100a10222def (py38 no-py39 !) +- body: size=505, sha1=eb823c293bedff0df4070b854e2c5cbb06d6ec62 (py39 !) ++ body: size=553, sha1=d5ac805b760ba754e26f29447da49798d10aba59 + % tar.bz2 and zip disallowed should both give 403 + 403 Archive type not allowed + content-type: text/html; charset=ascii +@@ -250,7 +250,7 @@ check http return codes (with deprecated + transfer-encoding: chunked + + body: size=506, sha1=1bd1f8e8d3701704bd4385038bd9c09b81c77f4e (py38 no-py39 !) +- body: size=503, sha1=2d8ce8bb3816603b9683a1804a5a02c11224cb01 (py39 !) ++ body: size=545, sha1=2e96ec202aec6122f60d048e05d21cc17500746c (py39 !) + % zip and tar.gz disallowed should both give 403 + 403 Archive type not allowed + content-type: text/html; charset=ascii +@@ -278,7 +278,7 @@ check http return codes (with deprecated + server: testing stub value + transfer-encoding: chunked + +- body: size=(1377|1461|1489), sha1=(677b14d3d048778d5eb5552c14a67e6192068650|be6d3983aa13dfe930361b2569291cdedd02b537|1897e496871aa89ad685a92b936f5fa0d008b9e8) (re) ++ body: size=2005, sha1=9d3ba755e98726859058ef606997e4e7d35886cc + % tar.gz and tar.bz2 disallowed should both give 403 + 403 Archive type not allowed + content-type: text/html; charset=ascii +@@ -345,38 +345,50 @@ invalid arch type should give 404 + > sys.stderr.write(str(e) + '\n') + > EOF + $ "$PYTHON" getarchive.py "$TIP" gz | gunzip | tar tf - 2>/dev/null ++ test-archive-1701ef1f1510/ + test-archive-1701ef1f1510/.hg_archival.txt + test-archive-1701ef1f1510/.hgsub + test-archive-1701ef1f1510/.hgsubstate + test-archive-1701ef1f1510/bar ++ test-archive-1701ef1f1510/baz/ + test-archive-1701ef1f1510/baz/bletch + test-archive-1701ef1f1510/foo ++ test-archive-1701ef1f1510/subrepo/ + test-archive-1701ef1f1510/subrepo/sub + $ "$PYTHON" getarchive.py "$TIP" bz2 | bunzip2 | tar tf - 2>/dev/null ++ test-archive-1701ef1f1510/ + test-archive-1701ef1f1510/.hg_archival.txt + test-archive-1701ef1f1510/.hgsub + test-archive-1701ef1f1510/.hgsubstate + test-archive-1701ef1f1510/bar ++ test-archive-1701ef1f1510/baz/ + test-archive-1701ef1f1510/baz/bletch + test-archive-1701ef1f1510/foo ++ test-archive-1701ef1f1510/subrepo/ + test-archive-1701ef1f1510/subrepo/sub + $ "$PYTHON" getarchive.py "$TIP" zip > archive.zip + $ unzip -t archive.zip + Archive: archive.zip ++ testing: test-archive-1701ef1f1510/ OK + testing: test-archive-1701ef1f1510/.hg_archival.txt*OK (glob) + testing: test-archive-1701ef1f1510/.hgsub*OK (glob) + testing: test-archive-1701ef1f1510/.hgsubstate*OK (glob) + testing: test-archive-1701ef1f1510/bar*OK (glob) ++ testing: test-archive-1701ef1f1510/baz/ OK + testing: test-archive-1701ef1f1510/baz/bletch*OK (glob) + testing: test-archive-1701ef1f1510/foo*OK (glob) ++ testing: test-archive-1701ef1f1510/subrepo/ OK + testing: test-archive-1701ef1f1510/subrepo/sub*OK (glob) + No errors detected in compressed data of archive.zip. + + test that we can download single directories and files + + $ "$PYTHON" getarchive.py "$TIP" gz baz | gunzip | tar tf - 2>/dev/null ++ test-archive-1701ef1f1510/ ++ test-archive-1701ef1f1510/baz/ + test-archive-1701ef1f1510/baz/bletch + $ "$PYTHON" getarchive.py "$TIP" gz foo | gunzip | tar tf - 2>/dev/null ++ test-archive-1701ef1f1510/ + test-archive-1701ef1f1510/foo + + test that we detect file patterns that match no files +@@ -393,10 +405,12 @@ test that we reject unsafe patterns + + $ hg archive -t tar test.tar + $ tar tf test.tar ++ test/ + test/.hg_archival.txt + test/.hgsub + test/.hgsubstate + test/bar ++ test/baz/ + test/baz/bletch + test/foo + +@@ -407,6 +421,7 @@ test that we reject unsafe patterns + archiving: bar 3/4 files (75.00%) + archiving: foo 4/4 files (100.00%) + $ bunzip2 -dc test.tar.bz2 | tar tf - 2>/dev/null ++ test/ + test/.hg_archival.txt + test/.hgsub + test/.hgsubstate +@@ -415,19 +430,23 @@ test that we reject unsafe patterns + + $ hg archive -t tgz -p %b-%h test-%h.tar.gz + $ gzip -dc test-$QTIP.tar.gz | tar tf - 2>/dev/null ++ test-1701ef1f1510/ + test-1701ef1f1510/.hg_archival.txt + test-1701ef1f1510/.hgsub + test-1701ef1f1510/.hgsubstate + test-1701ef1f1510/bar ++ test-1701ef1f1510/baz/ + test-1701ef1f1510/baz/bletch + test-1701ef1f1510/foo + + $ hg archive autodetected_test.tar + $ tar tf autodetected_test.tar ++ autodetected_test/ + autodetected_test/.hg_archival.txt + autodetected_test/.hgsub + autodetected_test/.hgsubstate + autodetected_test/bar ++ autodetected_test/baz/ + autodetected_test/baz/bletch + autodetected_test/foo + +@@ -435,10 +454,12 @@ The '-t' should override autodetection + + $ hg archive -t tar autodetect_override_test.zip + $ tar tf autodetect_override_test.zip ++ autodetect_override_test.zip/ + autodetect_override_test.zip/.hg_archival.txt + autodetect_override_test.zip/.hgsub + autodetect_override_test.zip/.hgsubstate + autodetect_override_test.zip/bar ++ autodetect_override_test.zip/baz/ + autodetect_override_test.zip/baz/bletch + autodetect_override_test.zip/foo + +@@ -477,16 +498,20 @@ rename them afterwards. + $ hg archive --config ui.archivemeta=false -t zip -r 2 test.zip + $ unzip -t test.zip + Archive: test.zip ++ testing: test/ OK + testing: test/bar*OK (glob) ++ testing: test/baz/ OK + testing: test/baz/bletch*OK (glob) + testing: test/foo*OK (glob) + No errors detected in compressed data of test.zip. + + $ hg archive -t tar - | tar tf - 2>/dev/null ++ test-1701ef1f1510/ + test-1701ef1f1510/.hg_archival.txt + test-1701ef1f1510/.hgsub + test-1701ef1f1510/.hgsubstate + test-1701ef1f1510/bar ++ test-1701ef1f1510/baz/ + test-1701ef1f1510/baz/bletch + test-1701ef1f1510/foo + +@@ -565,6 +590,7 @@ old file -- date clamped to 1980 + $ unzip -l ../old.zip | grep -v -- ----- | grep -E -v files$ + Archive: ../old.zip + \s*Length.* (re) ++ 0 1980-01-01 00:00 old/ + *172*80*00:00*old/.hg_archival.txt (glob) + *0*80*00:00*old/old (glob) + +diff --git a/tests/test-audit-path.t b/tests/test-audit-path.t +--- a/tests/test-audit-path.t ++++ b/tests/test-audit-path.t +@@ -75,15 +75,25 @@ Test that hg cat does not do anything wr + + unbundle tampered bundle + ++ ++We used to allow such unbundling, but we will no longer do so. We will use a ++tarball for the rest of the test. ++ + $ hg init target +- $ cd target +- $ hg unbundle "$TESTDIR/bundles/tampered.hg" ++ $ hg -R target unbundle "$TESTDIR/bundles/tampered.hg" + adding changesets + adding manifests + adding file changes +- added 5 changesets with 6 changes to 6 files (+4 heads) +- new changesets b7da9bf6b037:fc1393d727bc (5 drafts) +- (run 'hg heads' to see heads, 'hg merge' to merge) ++ transaction abort! ++ rollback completed ++ abort: path contains illegal component: ../test ++ [10] ++ $ rm -rf target ++ ++(the fortold tarball usage) ++ ++ $ tar xf $TESTDIR/bundles/tampered.tar ++ $ cd target + + attack .hg/test + +diff --git a/tests/test-commit.t b/tests/test-commit.t +--- a/tests/test-commit.t ++++ b/tests/test-commit.t +@@ -645,7 +645,9 @@ Test making empty commits + + verify pathauditor blocks evil filepaths + $ cat > evil-commit.py < from mercurial import context, hg, ui as uimod ++ > from mercurial import context, hg, pathutil, ui as uimod ++ > def yescard(*args, **kwargs): pass ++ > pathutil.pathauditor.__call__ = yescard + > notrc = u".h\u200cg".encode('utf-8') + b'/hgrc' + > u = uimod.ui.load() + > r = hg.repository(u, b'.') +@@ -670,7 +672,9 @@ verify pathauditor blocks evil filepaths + $ hg rollback -f + repository tip rolled back to revision 2 (undo commit) + $ cat > evil-commit.py < from mercurial import context, hg, ui as uimod ++ > from mercurial import context, hg, pathutil, ui as uimod ++ > def yescard(*args, **kwargs): pass ++ > pathutil.pathauditor.__call__ = yescard + > notrc = b"HG~1/hgrc" + > u = uimod.ui.load() + > r = hg.repository(u, b'.') +@@ -689,7 +693,9 @@ verify pathauditor blocks evil filepaths + $ hg rollback -f + repository tip rolled back to revision 2 (undo commit) + $ cat > evil-commit.py < from mercurial import context, hg, ui as uimod ++ > from mercurial import context, hg, pathutil, ui as uimod ++ > def yescard(*args, **kwargs): pass ++ > pathutil.pathauditor.__call__ = yescard + > notrc = b"HG8B6C~2/hgrc" + > u = uimod.ui.load() + > r = hg.repository(u, b'.') +diff --git a/tests/test-contrib-perf.t b/tests/test-contrib-perf.t +--- a/tests/test-contrib-perf.t ++++ b/tests/test-contrib-perf.t +@@ -278,7 +278,7 @@ perfstatus + $ hg perfprogress --total 1000 + $ hg perfrawfiles 2 + $ hg perfrevlogindex -c +- $ hg perfrevlogrevisions .hg/store/data/a.i ++ $ hg perfrevlogrevisions a + + #if no-rust + Cannot test in Rust because this these are highly invasive and expect a certain +diff --git a/tests/test-hg-sa-2026-001-symlink.t b/tests/test-hg-sa-2026-001-symlink.t +new file mode 100644 +--- /dev/null ++++ b/tests/test-hg-sa-2026-001-symlink.t +@@ -0,0 +1,1280 @@ ++==================================================================== ++Test mercurial behavior for malicious commit writing through symlink ++==================================================================== ++ ++Create a repo with building block for troubles ++============================================== ++ ++In itself the changes in this repository are not harmful, but combined on the ++wrong order, they can. ++ ++ $ cat << EOF >> $HGRCPATH ++ > [diff] ++ > git=yes ++ > EOF ++ ++ $ hg init base ++ $ cd base ++ $ cat << EOF >> README ++ > Small repository with file within a directory that is indeed a symlink ++ > EOF ++ $ hg add README ++ $ mkdir early-dir ++ $ echo "zephir" > early-dir/monkeys ++ $ hg add early-dir/monkeys ++ $ hg commit -m base ++ $ ln -s early-dir later-dir ++ $ hg add later-dir ++ $ hg commit -m link-early ++ $ hg up 'desc(base)' ++ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved ++ $ ln -s ../escape later-dir ++ $ hg add later-dir ++ $ hg commit -m link-escape ++ created new head ++ $ hg up 'desc(base)' ++ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved ++ $ mkdir later-dir ++ $ echo "babar" > later-dir/elephants ++ $ hg add later-dir/elephants ++ $ hg commit -m file-create ++ created new head ++ $ echo "celeste" >> later-dir/elephants ++ $ hg commit -m file-update ++ ++ $ hg log -G --patch ++ @ changeset: 4:4e637c77a46b ++ | tag: tip ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-update ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | --- a/later-dir/elephants ++ | +++ b/later-dir/elephants ++ | @@ -1,1 +1,2 @@ ++ | babar ++ | +celeste ++ | ++ o changeset: 3:3215058fb90d ++ | parent: 0:1d00bb1db649 ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-create ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | new file mode 100644 ++ | --- /dev/null ++ | +++ b/later-dir/elephants ++ | @@ -0,0 +1,1 @@ ++ | +babar ++ | ++ | o changeset: 2:37ce03bf784a ++ |/ parent: 0:1d00bb1db649 ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: link-escape ++ | ++ | diff --git a/later-dir b/later-dir ++ | new file mode 120000 ++ | --- /dev/null ++ | +++ b/later-dir ++ | @@ -0,0 +1,1 @@ ++ | +../escape ++ | \ No newline at end of file ++ | ++ | o changeset: 1:69964e60f6e8 ++ |/ user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: link-early ++ | ++ | diff --git a/later-dir b/later-dir ++ | new file mode 120000 ++ | --- /dev/null ++ | +++ b/later-dir ++ | @@ -0,0 +1,1 @@ ++ | +early-dir ++ | \ No newline at end of file ++ | ++ o changeset: 0:1d00bb1db649 ++ user: test ++ date: Thu Jan 01 00:00:00 1970 +0000 ++ summary: base ++ ++ diff --git a/README b/README ++ new file mode 100644 ++ --- /dev/null ++ +++ b/README ++ @@ -0,0 +1,1 @@ ++ +Small repository with file within a directory that is indeed a symlink ++ diff --git a/early-dir/monkeys b/early-dir/monkeys ++ new file mode 100644 ++ --- /dev/null ++ +++ b/early-dir/monkeys ++ @@ -0,0 +1,1 @@ ++ +zephir ++ ++ $ LINK_EARLY=`hg log -T '{node}' --rev 'desc("link-early")'` ++ $ LINK_ESCAPE=`hg log -T '{node}' --rev 'desc("link-escape")'` ++ $ FILE_CREATE=`hg log -T '{node}' --rev 'desc("file-create")'` ++ $ FILE_UPDATE=`hg log -T '{node}' --rev 'desc("file-update")'` ++ $ cd .. ++ ++ ++Create harmful repositories from these blocks ++============================================= ++ ++We use `hg import` to create bad history. We could (should) fix `hg import` to ++prevent this. However someone could still craft this kind of bad repository ++manually, so we still need to test Mercurial behavior on such repository. ++ ++Symlink replacing a directory ++----------------------------- ++ ++craft a repo where the change is made after the symlink ++ ++ $ hg clone --rev 0 base symlink-and-create ++ adding changesets ++ adding manifests ++ adding file changes ++ added 1 changesets with 2 changes to 2 files ++ new changesets 1d00bb1db649 ++ updating to branch default ++ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved ++ $ cd symlink-and-create ++ $ hg pull --update ../base --rev $LINK_EARLY ++ pulling from ../base ++ searching for changes ++ adding changesets ++ adding manifests ++ adding file changes ++ added 1 changesets with 1 changes to 1 files ++ new changesets 69964e60f6e8 ++ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved ++ $ hg -R ../base export --rev 'desc("file-create")' | hg import --bypass - ++ applying patch from stdin ++ $ hg up null ++ 0 files updated, 0 files merged, 3 files removed, 0 files unresolved ++ $ hg log -G --patch ++ o changeset: 2:4996a2538538 ++ | tag: tip ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-create ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | new file mode 100644 ++ | --- /dev/null ++ | +++ b/later-dir/elephants ++ | @@ -0,0 +1,1 @@ ++ | +babar ++ | ++ o changeset: 1:69964e60f6e8 ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: link-early ++ | ++ | diff --git a/later-dir b/later-dir ++ | new file mode 120000 ++ | --- /dev/null ++ | +++ b/later-dir ++ | @@ -0,0 +1,1 @@ ++ | +early-dir ++ | \ No newline at end of file ++ | ++ o changeset: 0:1d00bb1db649 ++ user: test ++ date: Thu Jan 01 00:00:00 1970 +0000 ++ summary: base ++ ++ diff --git a/README b/README ++ new file mode 100644 ++ --- /dev/null ++ +++ b/README ++ @@ -0,0 +1,1 @@ ++ +Small repository with file within a directory that is indeed a symlink ++ diff --git a/early-dir/monkeys b/early-dir/monkeys ++ new file mode 100644 ++ --- /dev/null ++ +++ b/early-dir/monkeys ++ @@ -0,0 +1,1 @@ ++ +zephir ++ ++ $ cd .. ++ ++same, but with a symlink escaping the directory ++ ++ $ hg clone --rev 0 base escape-symlink-and-create ++ adding changesets ++ adding manifests ++ adding file changes ++ added 1 changesets with 2 changes to 2 files ++ new changesets 1d00bb1db649 ++ updating to branch default ++ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved ++ $ cd escape-symlink-and-create ++ $ hg pull --update ../base --rev $LINK_ESCAPE ++ pulling from ../base ++ searching for changes ++ adding changesets ++ adding manifests ++ adding file changes ++ added 1 changesets with 1 changes to 1 files ++ new changesets 37ce03bf784a ++ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved ++ $ hg -R ../base export --rev 'desc("file-create")' | hg import --bypass - ++ applying patch from stdin ++ $ hg up null ++ 0 files updated, 0 files merged, 3 files removed, 0 files unresolved ++ $ hg log -G --patch ++ o changeset: 2:221afa782e66 ++ | tag: tip ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-create ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | new file mode 100644 ++ | --- /dev/null ++ | +++ b/later-dir/elephants ++ | @@ -0,0 +1,1 @@ ++ | +babar ++ | ++ o changeset: 1:37ce03bf784a ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: link-escape ++ | ++ | diff --git a/later-dir b/later-dir ++ | new file mode 120000 ++ | --- /dev/null ++ | +++ b/later-dir ++ | @@ -0,0 +1,1 @@ ++ | +../escape ++ | \ No newline at end of file ++ | ++ o changeset: 0:1d00bb1db649 ++ user: test ++ date: Thu Jan 01 00:00:00 1970 +0000 ++ summary: base ++ ++ diff --git a/README b/README ++ new file mode 100644 ++ --- /dev/null ++ +++ b/README ++ @@ -0,0 +1,1 @@ ++ +Small repository with file within a directory that is indeed a symlink ++ diff --git a/early-dir/monkeys b/early-dir/monkeys ++ new file mode 100644 ++ --- /dev/null ++ +++ b/early-dir/monkeys ++ @@ -0,0 +1,1 @@ ++ +zephir ++ ++ $ cd .. ++ ++silently replace a dir by a symlink ++------------------------------------ ++ ++craft a repo where the symlink is added afte the change ++ ++ $ hg clone --rev 0 base create-and-symlink ++ adding changesets ++ adding manifests ++ adding file changes ++ added 1 changesets with 2 changes to 2 files ++ new changesets 1d00bb1db649 ++ updating to branch default ++ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved ++ $ cd create-and-symlink ++ $ hg pull --update ../base --rev $FILE_CREATE ++ pulling from ../base ++ searching for changes ++ adding changesets ++ adding manifests ++ adding file changes ++ added 1 changesets with 1 changes to 1 files ++ new changesets 3215058fb90d ++ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved ++ $ hg -R ../base export --rev 'desc("link-early")' | hg import --bypass - ++ applying patch from stdin ++ $ hg up null ++ 0 files updated, 0 files merged, 3 files removed, 0 files unresolved ++ $ hg log -G --patch ++ o changeset: 2:e7ebd066a09f ++ | tag: tip ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: link-early ++ | ++ | diff --git a/later-dir b/later-dir ++ | new file mode 120000 ++ | --- /dev/null ++ | +++ b/later-dir ++ | @@ -0,0 +1,1 @@ ++ | +early-dir ++ | \ No newline at end of file ++ | ++ o changeset: 1:3215058fb90d ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-create ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | new file mode 100644 ++ | --- /dev/null ++ | +++ b/later-dir/elephants ++ | @@ -0,0 +1,1 @@ ++ | +babar ++ | ++ o changeset: 0:1d00bb1db649 ++ user: test ++ date: Thu Jan 01 00:00:00 1970 +0000 ++ summary: base ++ ++ diff --git a/README b/README ++ new file mode 100644 ++ --- /dev/null ++ +++ b/README ++ @@ -0,0 +1,1 @@ ++ +Small repository with file within a directory that is indeed a symlink ++ diff --git a/early-dir/monkeys b/early-dir/monkeys ++ new file mode 100644 ++ --- /dev/null ++ +++ b/early-dir/monkeys ++ @@ -0,0 +1,1 @@ ++ +zephir ++ ++ $ cd .. ++ ++same, but with a symlink escaping the directory ++ $ hg clone --rev 0 base escape-create-and-symlink ++ adding changesets ++ adding manifests ++ adding file changes ++ added 1 changesets with 2 changes to 2 files ++ new changesets 1d00bb1db649 ++ updating to branch default ++ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved ++ $ cd escape-create-and-symlink ++ $ hg -R ../base export --rev 'desc("file-create")' | hg import - ++ applying patch from stdin ++ $ hg -R ../base export --rev 'desc("link-escape")' | hg import --bypass - ++ applying patch from stdin ++ $ hg up null ++ 0 files updated, 0 files merged, 3 files removed, 0 files unresolved ++ $ hg log -G --patch ++ o changeset: 2:4481811fd564 ++ | tag: tip ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: link-escape ++ | ++ | diff --git a/later-dir b/later-dir ++ | new file mode 120000 ++ | --- /dev/null ++ | +++ b/later-dir ++ | @@ -0,0 +1,1 @@ ++ | +../escape ++ | \ No newline at end of file ++ | ++ o changeset: 1:3215058fb90d ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-create ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | new file mode 100644 ++ | --- /dev/null ++ | +++ b/later-dir/elephants ++ | @@ -0,0 +1,1 @@ ++ | +babar ++ | ++ o changeset: 0:1d00bb1db649 ++ user: test ++ date: Thu Jan 01 00:00:00 1970 +0000 ++ summary: base ++ ++ diff --git a/README b/README ++ new file mode 100644 ++ --- /dev/null ++ +++ b/README ++ @@ -0,0 +1,1 @@ ++ +Small repository with file within a directory that is indeed a symlink ++ diff --git a/early-dir/monkeys b/early-dir/monkeys ++ new file mode 100644 ++ --- /dev/null ++ +++ b/early-dir/monkeys ++ @@ -0,0 +1,1 @@ ++ +zephir ++ ++ $ cd .. ++ ++file update through a symlink ++----------------------------- ++ ++Combine the second with an update ++ ++craft a repo where a file is updated through a symlink ++ ++ $ cp -R create-and-symlink symlink-and-update ++ $ cd symlink-and-update ++XXX NEVER DO THIS AT HOME, necessary because --bypass does not take a --to flag ++ $ hg debugsetparents tip ++ $ hg -R ../base export --rev $FILE_UPDATE | hg import - --bypass ++ applying patch from stdin ++ $ hg up null ++ 0 files updated, 0 files merged, 4 files removed, 0 files unresolved ++ $ hg log -G --patch ++ o changeset: 3:7e66de0a4ac4 ++ | tag: tip ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-update ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | --- a/later-dir/elephants ++ | +++ b/later-dir/elephants ++ | @@ -1,1 +1,2 @@ ++ | babar ++ | +celeste ++ | ++ o changeset: 2:e7ebd066a09f ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: link-early ++ | ++ | diff --git a/later-dir b/later-dir ++ | new file mode 120000 ++ | --- /dev/null ++ | +++ b/later-dir ++ | @@ -0,0 +1,1 @@ ++ | +early-dir ++ | \ No newline at end of file ++ | ++ o changeset: 1:3215058fb90d ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-create ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | new file mode 100644 ++ | --- /dev/null ++ | +++ b/later-dir/elephants ++ | @@ -0,0 +1,1 @@ ++ | +babar ++ | ++ o changeset: 0:1d00bb1db649 ++ user: test ++ date: Thu Jan 01 00:00:00 1970 +0000 ++ summary: base ++ ++ diff --git a/README b/README ++ new file mode 100644 ++ --- /dev/null ++ +++ b/README ++ @@ -0,0 +1,1 @@ ++ +Small repository with file within a directory that is indeed a symlink ++ diff --git a/early-dir/monkeys b/early-dir/monkeys ++ new file mode 100644 ++ --- /dev/null ++ +++ b/early-dir/monkeys ++ @@ -0,0 +1,1 @@ ++ +zephir ++ ++ $ cd .. ++ ++same with escape ++ ++ $ cp -R escape-create-and-symlink escape-symlink-and-update ++ $ cd escape-symlink-and-update ++XXX NEVER DO THIS AT HOME, necessary because --bypass does not take a --to flag ++ $ hg debugsetparents tip ++ $ hg -R ../base export --rev $FILE_UPDATE | hg import - --bypass ++ applying patch from stdin ++ $ hg up null ++ 0 files updated, 0 files merged, 4 files removed, 0 files unresolved ++ $ hg log -G --patch ++ o changeset: 3:127003b63449 ++ | tag: tip ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-update ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | --- a/later-dir/elephants ++ | +++ b/later-dir/elephants ++ | @@ -1,1 +1,2 @@ ++ | babar ++ | +celeste ++ | ++ o changeset: 2:4481811fd564 ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: link-escape ++ | ++ | diff --git a/later-dir b/later-dir ++ | new file mode 120000 ++ | --- /dev/null ++ | +++ b/later-dir ++ | @@ -0,0 +1,1 @@ ++ | +../escape ++ | \ No newline at end of file ++ | ++ o changeset: 1:3215058fb90d ++ | user: test ++ | date: Thu Jan 01 00:00:00 1970 +0000 ++ | summary: file-create ++ | ++ | diff --git a/later-dir/elephants b/later-dir/elephants ++ | new file mode 100644 ++ | --- /dev/null ++ | +++ b/later-dir/elephants ++ | @@ -0,0 +1,1 @@ ++ | +babar ++ | ++ o changeset: 0:1d00bb1db649 ++ user: test ++ date: Thu Jan 01 00:00:00 1970 +0000 ++ summary: base ++ ++ diff --git a/README b/README ++ new file mode 100644 ++ --- /dev/null ++ +++ b/README ++ @@ -0,0 +1,1 @@ ++ +Small repository with file within a directory that is indeed a symlink ++ diff --git a/early-dir/monkeys b/early-dir/monkeys ++ new file mode 100644 ++ --- /dev/null ++ +++ b/early-dir/monkeys ++ @@ -0,0 +1,1 @@ ++ +zephir ++ ++ $ cd .. ++ ++ ++Generation of harmful archive and patch ++======================================= ++ ++ $ for repo_case in symlink-and-create create-and-symlink symlink-and-update escape-symlink-and-create escape-create-and-symlink escape-symlink-and-update ; do ++ > hg -R $repo_case archive --type tar --rev tip $repo_case.tar; ++ > hg -R $repo_case archive --type zip --rev tip $repo_case.zip; ++ > if echo $repo_case | grep update > /dev/null; then ++ > base_rev=1 ++ > else ++ > base_rev=0 ++ > fi ++ > hg -R $repo_case diff --from $base_rev --to tip > $repo_case.diff ++ > done ++ ++Inspect generated content ++========================= ++ ++ $ tar tf create-and-symlink.tar ++ create-and-symlink/ ++ create-and-symlink/.hg_archival.txt ++ create-and-symlink/README ++ create-and-symlink/early-dir/ ++ create-and-symlink/early-dir/monkeys ++ create-and-symlink/later-dir/ ++ create-and-symlink/later-dir/elephants ++ create-and-symlink/later-dir ++ ++ $ tar tf symlink-and-create.tar ++ symlink-and-create/ ++ symlink-and-create/.hg_archival.txt ++ symlink-and-create/README ++ symlink-and-create/early-dir/ ++ symlink-and-create/early-dir/monkeys ++ symlink-and-create/later-dir/ ++ symlink-and-create/later-dir/elephants ++ symlink-and-create/later-dir ++ ++ $ tar tf symlink-and-update.tar ++ symlink-and-update/ ++ symlink-and-update/.hg_archival.txt ++ symlink-and-update/README ++ symlink-and-update/early-dir/ ++ symlink-and-update/early-dir/monkeys ++ symlink-and-update/later-dir/ ++ symlink-and-update/later-dir/elephants ++ symlink-and-update/later-dir ++ ++ $ tar tf escape-create-and-symlink.tar ++ escape-create-and-symlink/ ++ escape-create-and-symlink/.hg_archival.txt ++ escape-create-and-symlink/README ++ escape-create-and-symlink/early-dir/ ++ escape-create-and-symlink/early-dir/monkeys ++ escape-create-and-symlink/later-dir/ ++ escape-create-and-symlink/later-dir/elephants ++ escape-create-and-symlink/later-dir ++ ++ $ tar tf escape-symlink-and-create.tar ++ escape-symlink-and-create/ ++ escape-symlink-and-create/.hg_archival.txt ++ escape-symlink-and-create/README ++ escape-symlink-and-create/early-dir/ ++ escape-symlink-and-create/early-dir/monkeys ++ escape-symlink-and-create/later-dir/ ++ escape-symlink-and-create/later-dir/elephants ++ escape-symlink-and-create/later-dir ++ ++ $ tar tf escape-symlink-and-update.tar ++ escape-symlink-and-update/ ++ escape-symlink-and-update/.hg_archival.txt ++ escape-symlink-and-update/README ++ escape-symlink-and-update/early-dir/ ++ escape-symlink-and-update/early-dir/monkeys ++ escape-symlink-and-update/later-dir/ ++ escape-symlink-and-update/later-dir/elephants ++ escape-symlink-and-update/later-dir ++ ++ $ unzip -t create-and-symlink.zip ++ Archive: create-and-symlink.zip ++ testing: create-and-symlink/ OK ++ testing: create-and-symlink/.hg_archival.txt OK ++ testing: create-and-symlink/README OK ++ testing: create-and-symlink/early-dir/ OK ++ testing: create-and-symlink/early-dir/monkeys OK ++ testing: create-and-symlink/later-dir/ OK ++ testing: create-and-symlink/later-dir/elephants OK ++ testing: create-and-symlink/later-dir OK ++ No errors detected in compressed data of create-and-symlink.zip. ++ ++ $ unzip -t symlink-and-create.zip ++ Archive: symlink-and-create.zip ++ testing: symlink-and-create/ OK ++ testing: symlink-and-create/.hg_archival.txt OK ++ testing: symlink-and-create/README OK ++ testing: symlink-and-create/early-dir/ OK ++ testing: symlink-and-create/early-dir/monkeys OK ++ testing: symlink-and-create/later-dir/ OK ++ testing: symlink-and-create/later-dir/elephants OK ++ testing: symlink-and-create/later-dir OK ++ No errors detected in compressed data of symlink-and-create.zip. ++ ++ $ unzip -t symlink-and-update.zip ++ Archive: symlink-and-update.zip ++ testing: symlink-and-update/ OK ++ testing: symlink-and-update/.hg_archival.txt OK ++ testing: symlink-and-update/README OK ++ testing: symlink-and-update/early-dir/ OK ++ testing: symlink-and-update/early-dir/monkeys OK ++ testing: symlink-and-update/later-dir/ OK ++ testing: symlink-and-update/later-dir/elephants OK ++ testing: symlink-and-update/later-dir OK ++ No errors detected in compressed data of symlink-and-update.zip. ++ ++ $ unzip -t escape-create-and-symlink.zip ++ Archive: escape-create-and-symlink.zip ++ testing: escape-create-and-symlink/ OK ++ testing: escape-create-and-symlink/.hg_archival.txt OK ++ testing: escape-create-and-symlink/README OK ++ testing: escape-create-and-symlink/early-dir/ OK ++ testing: escape-create-and-symlink/early-dir/monkeys OK ++ testing: escape-create-and-symlink/later-dir/ OK ++ testing: escape-create-and-symlink/later-dir/elephants OK ++ testing: escape-create-and-symlink/later-dir OK ++ No errors detected in compressed data of escape-create-and-symlink.zip. ++ ++ $ unzip -t escape-symlink-and-create.zip ++ Archive: escape-symlink-and-create.zip ++ testing: escape-symlink-and-create/ OK ++ testing: escape-symlink-and-create/.hg_archival.txt OK ++ testing: escape-symlink-and-create/README OK ++ testing: escape-symlink-and-create/early-dir/ OK ++ testing: escape-symlink-and-create/early-dir/monkeys OK ++ testing: escape-symlink-and-create/later-dir/ OK ++ testing: escape-symlink-and-create/later-dir/elephants OK ++ testing: escape-symlink-and-create/later-dir OK ++ No errors detected in compressed data of escape-symlink-and-create.zip. ++ ++ $ unzip -t escape-symlink-and-update.zip ++ Archive: escape-symlink-and-update.zip ++ testing: escape-symlink-and-update/ OK ++ testing: escape-symlink-and-update/.hg_archival.txt OK ++ testing: escape-symlink-and-update/README OK ++ testing: escape-symlink-and-update/early-dir/ OK ++ testing: escape-symlink-and-update/early-dir/monkeys OK ++ testing: escape-symlink-and-update/later-dir/ OK ++ testing: escape-symlink-and-update/later-dir/elephants OK ++ testing: escape-symlink-and-update/later-dir OK ++ No errors detected in compressed data of escape-symlink-and-update.zip. ++ ++ $ cat create-and-symlink.diff ++ diff --git a/later-dir b/later-dir ++ new file mode 120000 ++ --- /dev/null ++ +++ b/later-dir ++ @@ -0,0 +1,1 @@ ++ +early-dir ++ \ No newline at end of file ++ diff --git a/later-dir/elephants b/later-dir/elephants ++ new file mode 100644 ++ --- /dev/null ++ +++ b/later-dir/elephants ++ @@ -0,0 +1,1 @@ ++ +babar ++ ++ $ cat symlink-and-create.diff ++ diff --git a/later-dir b/later-dir ++ new file mode 120000 ++ --- /dev/null ++ +++ b/later-dir ++ @@ -0,0 +1,1 @@ ++ +early-dir ++ \ No newline at end of file ++ diff --git a/later-dir/elephants b/later-dir/elephants ++ new file mode 100644 ++ --- /dev/null ++ +++ b/later-dir/elephants ++ @@ -0,0 +1,1 @@ ++ +babar ++ ++ $ cat symlink-and-update.diff ++ diff --git a/later-dir b/later-dir ++ new file mode 120000 ++ --- /dev/null ++ +++ b/later-dir ++ @@ -0,0 +1,1 @@ ++ +early-dir ++ \ No newline at end of file ++ diff --git a/later-dir/elephants b/later-dir/elephants ++ --- a/later-dir/elephants ++ +++ b/later-dir/elephants ++ @@ -1,1 +1,2 @@ ++ babar ++ +celeste ++ ++ $ cat escape-create-and-symlink.diff ++ diff --git a/later-dir b/later-dir ++ new file mode 120000 ++ --- /dev/null ++ +++ b/later-dir ++ @@ -0,0 +1,1 @@ ++ +../escape ++ \ No newline at end of file ++ diff --git a/later-dir/elephants b/later-dir/elephants ++ new file mode 100644 ++ --- /dev/null ++ +++ b/later-dir/elephants ++ @@ -0,0 +1,1 @@ ++ +babar ++ ++ $ cat escape-symlink-and-create.diff ++ diff --git a/later-dir b/later-dir ++ new file mode 120000 ++ --- /dev/null ++ +++ b/later-dir ++ @@ -0,0 +1,1 @@ ++ +../escape ++ \ No newline at end of file ++ diff --git a/later-dir/elephants b/later-dir/elephants ++ new file mode 100644 ++ --- /dev/null ++ +++ b/later-dir/elephants ++ @@ -0,0 +1,1 @@ ++ +babar ++ ++ $ cat escape-symlink-and-update.diff ++ diff --git a/later-dir b/later-dir ++ new file mode 120000 ++ --- /dev/null ++ +++ b/later-dir ++ @@ -0,0 +1,1 @@ ++ +../escape ++ \ No newline at end of file ++ diff --git a/later-dir/elephants b/later-dir/elephants ++ --- a/later-dir/elephants ++ +++ b/later-dir/elephants ++ @@ -1,1 +1,2 @@ ++ babar ++ +celeste ++ ++Usage of harmful archive and patch ++================================== ++ ++A recent enough tar refuse to escape in parent directories, but it still follow ++simlink within the untar. so not great. ++ ++Same apply for `patch` ++ ++ $ test_exploit_bad_artifact () { ++ > cd $TESTTMP ++ > if echo $1 | grep update > /dev/null; then ++ > base_rev="file-create" ++ > else ++ > base_rev="base" ++ > fi ++ > if echo $1 | grep escape > /dev/null; then ++ > update_dest="../escape/" ++ > else ++ > update_dest="early-dir/" ++ > fi ++ > mkdir -p exploit-$1/untar/escape ++ > echo foo > exploit-$1/untar/escape/outside ++ > cd exploit-$1/untar/ ++ > echo "===" listing tarfile ++ > tar tf $TESTTMP/$1.tar ++ > echo "===" extracting tar file ++ > tar xf $TESTTMP/$1.tar ++ > echo "===" resulting file system state ++ > echo "=" symlink/dir status ++ > f --type */later-dir ++ > echo "=" listing dir ++ > ls -1 */later-dir/* ++ > echo "=" listing file system ++ > f --recurse --type --size . ++ > cd .. ++ > ++ > mkdir -p patch/escape ++ > echo foo > patch/escape/outside ++ > cd patch ++ > echo "===" applying the patch ++ > hg -R $TESTTMP/$1 archive --rev "desc(\"$base_rev\")" files ++ > cd files ++ > if [ -f later-dir/elephants ]; then ++ > mv later-dir/elephants $update_dest ++ > rmdir later-dir/ ++ > fi ++ > patch -p 1 < $TESTTMP/$1.diff ++ > cd .. ++ > echo "===" resulting file system state ++ > echo "=" reading ++ > readlink.py files/later-dir ++ > echo "=" listing ++ > ls -1 files/later-dir/* ++ > echo "=" symlink/dir status ++ > [ -f files/early-dir/elephants ] && readlink.py */later-dir ++ > echo "=" existing file status ++ > [ -f files/early-dir/elephants ] && cat files/early-dir/elephants ++ > [ -f escape/elephants ] && cat escape/elephants ++ > echo "=" listing file system ++ > f --recurse --type --size . ++ > cd $TESTTMP ++ > } ++ ++ $ test_exploit_bad_artifact symlink-and-create ++ === listing tarfile ++ symlink-and-create/ ++ symlink-and-create/.hg_archival.txt ++ symlink-and-create/README ++ symlink-and-create/early-dir/ ++ symlink-and-create/early-dir/monkeys ++ symlink-and-create/later-dir/ ++ symlink-and-create/later-dir/elephants ++ symlink-and-create/later-dir ++ === extracting tar file ++ tar: symlink-and-create/later-dir: Cannot create symlink to 'early-dir': File exists ++ tar: Exiting with failure status due to previous errors ++ === resulting file system state ++ = symlink/dir status ++ symlink-and-create/later-dir: directory with 1 files ++ = listing dir ++ symlink-and-create/later-dir/elephants ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./symlink-and-create: directory with 4 files ++ ./symlink-and-create/.hg_archival.txt: file, size=172 ++ ./symlink-and-create/README: file, size=71 ++ ./symlink-and-create/early-dir: directory with 1 files ++ ./symlink-and-create/early-dir/monkeys: file, size=7 ++ ./symlink-and-create/later-dir: directory with 1 files ++ ./symlink-and-create/later-dir/elephants: file, size=6 ++ === applying the patch ++ patching symbolic link later-dir ++ patching file later-dir/elephants ++ === resulting file system state ++ = reading ++ files/later-dir -> early-dir ++ = listing ++ files/later-dir/elephants ++ files/later-dir/monkeys ++ = symlink/dir status ++ files/later-dir -> early-dir ++ = existing file status ++ babar ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 2 files ++ ./files/early-dir/elephants: file, size=6 ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ ++ $ test_exploit_bad_artifact create-and-symlink ++ === listing tarfile ++ create-and-symlink/ ++ create-and-symlink/.hg_archival.txt ++ create-and-symlink/README ++ create-and-symlink/early-dir/ ++ create-and-symlink/early-dir/monkeys ++ create-and-symlink/later-dir/ ++ create-and-symlink/later-dir/elephants ++ create-and-symlink/later-dir ++ === extracting tar file ++ tar: create-and-symlink/later-dir: Cannot create symlink to 'early-dir': File exists ++ tar: Exiting with failure status due to previous errors ++ === resulting file system state ++ = symlink/dir status ++ create-and-symlink/later-dir: directory with 1 files ++ = listing dir ++ create-and-symlink/later-dir/elephants ++ = listing file system ++ .: directory with 2 files ++ ./create-and-symlink: directory with 4 files ++ ./create-and-symlink/.hg_archival.txt: file, size=172 ++ ./create-and-symlink/README: file, size=71 ++ ./create-and-symlink/early-dir: directory with 1 files ++ ./create-and-symlink/early-dir/monkeys: file, size=7 ++ ./create-and-symlink/later-dir: directory with 1 files ++ ./create-and-symlink/later-dir/elephants: file, size=6 ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ === applying the patch ++ patching symbolic link later-dir ++ patching file later-dir/elephants ++ === resulting file system state ++ = reading ++ files/later-dir -> early-dir ++ = listing ++ files/later-dir/elephants ++ files/later-dir/monkeys ++ = symlink/dir status ++ files/later-dir -> early-dir ++ = existing file status ++ babar ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 2 files ++ ./files/early-dir/elephants: file, size=6 ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ ++ $ test_exploit_bad_artifact symlink-and-update ++ === listing tarfile ++ symlink-and-update/ ++ symlink-and-update/.hg_archival.txt ++ symlink-and-update/README ++ symlink-and-update/early-dir/ ++ symlink-and-update/early-dir/monkeys ++ symlink-and-update/later-dir/ ++ symlink-and-update/later-dir/elephants ++ symlink-and-update/later-dir ++ === extracting tar file ++ tar: symlink-and-update/later-dir: Cannot create symlink to 'early-dir': File exists ++ tar: Exiting with failure status due to previous errors ++ === resulting file system state ++ = symlink/dir status ++ symlink-and-update/later-dir: directory with 1 files ++ = listing dir ++ symlink-and-update/later-dir/elephants ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./symlink-and-update: directory with 4 files ++ ./symlink-and-update/.hg_archival.txt: file, size=172 ++ ./symlink-and-update/README: file, size=71 ++ ./symlink-and-update/early-dir: directory with 1 files ++ ./symlink-and-update/early-dir/monkeys: file, size=7 ++ ./symlink-and-update/later-dir: directory with 1 files ++ ./symlink-and-update/later-dir/elephants: file, size=14 ++ === applying the patch ++ patching symbolic link later-dir ++ patching file later-dir/elephants ++ === resulting file system state ++ = reading ++ files/later-dir -> early-dir ++ = listing ++ files/later-dir/elephants ++ files/later-dir/monkeys ++ = symlink/dir status ++ files/later-dir -> early-dir ++ = existing file status ++ babar ++ celeste ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 2 files ++ ./files/early-dir/elephants: file, size=14 ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ ++ $ test_exploit_bad_artifact escape-symlink-and-create ++ === listing tarfile ++ escape-symlink-and-create/ ++ escape-symlink-and-create/.hg_archival.txt ++ escape-symlink-and-create/README ++ escape-symlink-and-create/early-dir/ ++ escape-symlink-and-create/early-dir/monkeys ++ escape-symlink-and-create/later-dir/ ++ escape-symlink-and-create/later-dir/elephants ++ escape-symlink-and-create/later-dir ++ === extracting tar file ++ tar: escape-symlink-and-create/later-dir: Cannot open: File exists ++ tar: Exiting with failure status due to previous errors ++ === resulting file system state ++ = symlink/dir status ++ escape-symlink-and-create/later-dir: directory with 1 files ++ = listing dir ++ escape-symlink-and-create/later-dir/elephants ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./escape-symlink-and-create: directory with 4 files ++ ./escape-symlink-and-create/.hg_archival.txt: file, size=172 ++ ./escape-symlink-and-create/README: file, size=71 ++ ./escape-symlink-and-create/early-dir: directory with 1 files ++ ./escape-symlink-and-create/early-dir/monkeys: file, size=7 ++ ./escape-symlink-and-create/later-dir: directory with 1 files ++ ./escape-symlink-and-create/later-dir/elephants: file, size=6 ++ === applying the patch ++ patching symbolic link later-dir ++ Invalid file name later-dir/elephants -- skipping patch ++ === resulting file system state ++ = reading ++ files/later-dir -> ../escape ++ = listing ++ files/later-dir/outside ++ = symlink/dir status ++ = existing file status ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 1 files ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ ++ $ test_exploit_bad_artifact escape-create-and-symlink ++ === listing tarfile ++ escape-create-and-symlink/ ++ escape-create-and-symlink/.hg_archival.txt ++ escape-create-and-symlink/README ++ escape-create-and-symlink/early-dir/ ++ escape-create-and-symlink/early-dir/monkeys ++ escape-create-and-symlink/later-dir/ ++ escape-create-and-symlink/later-dir/elephants ++ escape-create-and-symlink/later-dir ++ === extracting tar file ++ tar: escape-create-and-symlink/later-dir: Cannot open: File exists ++ tar: Exiting with failure status due to previous errors ++ === resulting file system state ++ = symlink/dir status ++ escape-create-and-symlink/later-dir: directory with 1 files ++ = listing dir ++ escape-create-and-symlink/later-dir/elephants ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./escape-create-and-symlink: directory with 4 files ++ ./escape-create-and-symlink/.hg_archival.txt: file, size=172 ++ ./escape-create-and-symlink/README: file, size=71 ++ ./escape-create-and-symlink/early-dir: directory with 1 files ++ ./escape-create-and-symlink/early-dir/monkeys: file, size=7 ++ ./escape-create-and-symlink/later-dir: directory with 1 files ++ ./escape-create-and-symlink/later-dir/elephants: file, size=6 ++ === applying the patch ++ patching symbolic link later-dir ++ Invalid file name later-dir/elephants -- skipping patch ++ === resulting file system state ++ = reading ++ files/later-dir -> ../escape ++ = listing ++ files/later-dir/outside ++ = symlink/dir status ++ = existing file status ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 1 files ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ ++ $ test_exploit_bad_artifact escape-symlink-and-update ++ === listing tarfile ++ escape-symlink-and-update/ ++ escape-symlink-and-update/.hg_archival.txt ++ escape-symlink-and-update/README ++ escape-symlink-and-update/early-dir/ ++ escape-symlink-and-update/early-dir/monkeys ++ escape-symlink-and-update/later-dir/ ++ escape-symlink-and-update/later-dir/elephants ++ escape-symlink-and-update/later-dir ++ === extracting tar file ++ tar: escape-symlink-and-update/later-dir: Cannot open: File exists ++ tar: Exiting with failure status due to previous errors ++ === resulting file system state ++ = symlink/dir status ++ escape-symlink-and-update/later-dir: directory with 1 files ++ = listing dir ++ escape-symlink-and-update/later-dir/elephants ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./escape-symlink-and-update: directory with 4 files ++ ./escape-symlink-and-update/.hg_archival.txt: file, size=172 ++ ./escape-symlink-and-update/README: file, size=71 ++ ./escape-symlink-and-update/early-dir: directory with 1 files ++ ./escape-symlink-and-update/early-dir/monkeys: file, size=7 ++ ./escape-symlink-and-update/later-dir: directory with 1 files ++ ./escape-symlink-and-update/later-dir/elephants: file, size=14 ++ === applying the patch ++ patching symbolic link later-dir ++ can't find file to patch at input line 10 ++ Perhaps you used the wrong -p or --strip option? ++ The text leading up to this was: ++ -------------------------- ++ |diff --git a/later-dir/elephants b/later-dir/elephants ++ |--- a/later-dir/elephants ++ |+++ b/later-dir/elephants ++ -------------------------- ++ File to patch: ++ Skip this patch? [y] ++ Skipping patch. ++ 1 out of 1 hunk ignored ++ === resulting file system state ++ = reading ++ files/later-dir -> ../escape ++ = listing ++ files/later-dir/elephants ++ files/later-dir/outside ++ = symlink/dir status ++ = existing file status ++ babar ++ = listing file system ++ .: directory with 2 files ++ ./escape: directory with 2 files ++ ./escape/elephants: file, size=6 ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 1 files ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ ++ ++Combining archive and export | patch -p 1 ++========================================= ++ ++We use archive to create valid files (could be a checkout), then use `hg export ++| path` to apply a patch valid in itself. ++ ++In themself, the initial archive is valid, from a valid commit. The patch has ++nothing suspicious in it (be come from a bad commit). ++ ++A recent enough version of patch don't escape through symlink, but could still ++do bad things internally. ++ ++ $ test_exploit_combine_good_artifact () { ++ > cd $TESTTMP ++ > mkdir -p exploit-simple-$1/escape ++ > echo foo > exploit-simple-$1/escape/outside ++ > cd exploit-simple-$1 ++ > hg -R $TESTTMP/$1 archive --rev "tip~1" --type tar files.tar ++ > tar xf files.tar ++ > rm files.tar ++ > echo "===" listing resulting fs before ++ > f --recurse . --type --size ++ > echo "===" reading link ++ > readlink.py files/later-dir ++ > echo "===" listing directory ++ > readlink.py files/later-dir ++ > ls files/later-dir/* ++ > echo "===" patching ++ > cd files ++ > hg -R $TESTTMP/$1 export tip | patch -p 1 ++ > echo "===" listing resulting fs after ++ > cd .. ++ > f --recurse . --type --size ++ > cd $TESTTMP ++ > } ++ ++ $ test_exploit_combine_good_artifact symlink-and-create ++ === listing resulting fs before ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 1 files ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ === reading link ++ files/later-dir -> early-dir ++ === listing directory ++ files/later-dir -> early-dir ++ files/later-dir/monkeys ++ === patching ++ patching file later-dir/elephants ++ === listing resulting fs after ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 2 files ++ ./files/early-dir/elephants: file, size=6 ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ ++ $ test_exploit_combine_good_artifact escape-symlink-and-create ++ === listing resulting fs before ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 1 files ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link ++ === reading link ++ files/later-dir -> ../escape ++ === listing directory ++ files/later-dir -> ../escape ++ files/later-dir/outside ++ === patching ++ Invalid file name later-dir/elephants -- skipping patch ++ === listing resulting fs after ++ .: directory with 2 files ++ ./escape: directory with 1 files ++ ./escape/outside: file, size=4 ++ ./files: directory with 4 files ++ ./files/.hg_archival.txt: file, size=172 ++ ./files/README: file, size=71 ++ ./files/early-dir: directory with 1 files ++ ./files/early-dir/monkeys: file, size=7 ++ ./files/later-dir: link +diff --git a/tests/test-hg-sa-2026-001-track-bad-file.t b/tests/test-hg-sa-2026-001-track-bad-file.t +new file mode 100644 +--- /dev/null ++++ b/tests/test-hg-sa-2026-001-track-bad-file.t +@@ -0,0 +1,215 @@ ++=============================== ++Check attack vector for CVE-XXX ++=============================== ++ ++This test check various attack vector to exploit a repository with malicious ++changesets storing content for `.hg/hgrc`. ++ ++While the data-schema cannot prevent the crafting of such malicious changesets, ++Mercurial should prevent their exploitation. In addition we should detect such ++malicious changesets early and prevent their propagation. ++ ++The `hg archive` code provides an attack vector for this (CVE-XXX) ++ ++We run this test case with various format variant as their tend to use ++different code path. This list should be extended whenever new significant ++variant are added. ++ ++#testcases storeless prev-delta general-delta sparse-delta compzstd ++ ++ $ FORMAT=$TESTCASE ++ ++ $ cat << EOF >> $HGRCPATH ++ > [storage] ++ > all-slow-path = allow ++ > EOF ++ ++Rust has slightly more precises errors and catch the issue sooner in a few ++case, so we have to use dedicated matching from time to time. ++ ++ ++Some flavor don't support zstd and so we need to skip these cases ++ ++ $ skip_zstd() { ++ > echo 'skipped: missing zstd support' ++ > exit 80 ++ > } ++ ++#if no-zstd compzstd ++ $ skip_zstd ++#endif ++ ++Attack from a pre-built repository ++================================== ++ ++Get the pre-built repository ++ ++ $ tar xf $TESTDIR/bundles/evil-repo-$FORMAT.tar ++ $ mv evil-repo-* evil-repo ++ $ cd evil-repo ++ ++ ++Try attack within the working copy with update ++---------------------------------------------- ++ ++attack through update while another hgrc exist ++ ++ ++#if rust no-storeless ++ $ hg update 1 ++ abort: path '.hg/hgrc' is inside the '.hg' folder ++ [10] ++ $ hg identify ++ 000000000000 ++#else ++ $ hg update 1 ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ $ hg identify ++ 000000000000 ++#endif ++ ++attack through revert while another hgrc exist ++ ++ $ hg up null --quiet --clean ++ $ hg revert --all --rev 1 ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ ++update while no another hgrc exist ++ ++ $ hg up null --quiet --clean ++ $ rm -f .hg/hgrc ++ $ hg update 1 ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ $ hg identify ++ 000000000000 ++ ++attack through revert while no other hgrc exist ++ ++ $ hg up null --quiet --clean ++ $ rm -f .hg/hgrc ++ ++ $ hg revert --all --rev 1 ++ adding .hg/hgrc ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ ++Try attack through an exported archive ++-------------------------------------- ++ ++create an evil archive ++ ++ $ hg archive -t tar -r 1 ../evil-archive.tar ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ $ cd .. ++ $ test -f evil-archive.tar && tar xf evil-archive.tar ++ [1] ++ ++ ++Attack with the evil archive ++ ++ $ hg -R evil-archive identify ++ abort: repository evil-archive not found ++ [255] ++ ++ ++Attack over the wire ++==================== ++ ++Create a repository in the target format ++ ++ $ cp $HGRCPATH rc.bck ++ $ cat $TESTDIR/bundles/rc-variants/$FORMAT.rc >> $HGRCPATH ++ $ hg init target-repo ++ ++Pull the base change in it ++ ++ $ hg -R target-repo unbundle $TESTDIR/bundles/base-bundle.hg --quiet ++ $ hg -R target-repo log -T '{rev}\n' ++ 0 ++ ++Pulling the evil change should fails ++ ++ $ hg -R target-repo unbundle $TESTDIR/bundles/evil-bundle.hg --quiet ++ transaction abort! ++ rollback completed ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ $ hg -R target-repo log -T '{rev}\n' ++ 0 ++ ++Bundling the evil changeset out ++=============================== ++ ++ $ hg -R evil-repo bundle --all out-bundle.hg ++ 2 changesets found ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ ++Streamcloning the evil changeset ++================================ ++ ++Stream cloning from a corrupted repository ++------------------------------------------ ++ ++ $ hg clone --stream ssh://user@dummy/evil-repo/ streamed-repo --noupdate ++ streaming all changes ++ remote: abort: path contains illegal component: .hg/hgrc ++ abort: pull failed on remote ++ [100] ++ ++Generating a corrupted stream bundle from a corrupted repository (v1 format) ++---------------------------------------------------------------------------- ++ ++ $ hg --repository evil-repo debugcreatestreamclonebundle evil-stream-v1.hg ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ ++Generating a corrupted stream bundle from a corrupted repository (v2 format) ++---------------------------------------------------------------------------- ++ ++ $ hg --repository evil-repo bundle --type 'none-v2;stream=v2;changegroup=0' --all evil-stream-v2.hg ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ ++Applying a corrupted stream bundle v1 format ++-------------------------------------------- ++ ++ $ hg init stream-v1-target-repo ++ $ cp $TESTDIR/bundles/rc-variants/$FORMAT.rc stream-v1-target-repo/.hg/hgrc ++ $ hg -R stream-v1-target-repo/ \ ++ > debugapplystreamclonebundle \ ++ > $TESTDIR/bundles/evil-stream-v1-$FORMAT.hg ++ * files to transfer, * of data (glob) ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ ++Applying a corrupted stream bundle v2 format ++-------------------------------------------- ++ ++ $ hg init stream-v2-target-repo ++ $ cp $TESTDIR/bundles/rc-variants/$FORMAT.rc stream-v2-target-repo/.hg/hgrc ++ $ hg -R stream-v2-target-repo/ unbundle $TESTDIR/bundles/evil-stream-v2-$FORMAT.hg ++ * files to transfer, * of data (glob) ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ ++Local clone ++=========== ++ ++with the same config ++ ++ $ hg clone evil-repo same-local-clone --noupdate ++ abort: path contains illegal component: .hg/hgrc ++ [10] ++ ++with a modern config ++ ++ $ cp rc.bck $HGRCPATH ++ ++ $ hg clone evil-repo modern-local-clone --noupdate ++ abort: path contains illegal component: .hg/hgrc ++ [10] +diff --git a/tests/test-largefiles-wireproto.t b/tests/test-largefiles-wireproto.t +--- a/tests/test-largefiles-wireproto.t ++++ b/tests/test-largefiles-wireproto.t +@@ -229,6 +229,7 @@ Archive contains largefiles + ... f.write(urllibcompat.urlreq.urlopen(u).read()) and None + $ unzip -t archive.zip + Archive: archive.zip ++ testing: empty-default/ OK + testing: empty-default/.hg_archival.txt*OK (glob) + testing: empty-default/f1*OK (glob) + No errors detected in compressed data of archive.zip. +diff --git a/tests/test-narrow-archive.t b/tests/test-narrow-archive.t +--- a/tests/test-narrow-archive.t ++++ b/tests/test-narrow-archive.t +@@ -28,5 +28,6 @@ The tar should only contain f1 and f2 + $ cd narrowclone1 + $ hg archive -t tgz repo.tgz + $ tar tfz repo.tgz ++ repo/ + repo/f1 + repo/f2 +diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t +--- a/tests/test-subrepo-deep-nested-change.t ++++ b/tests/test-subrepo-deep-nested-change.t +@@ -839,9 +839,11 @@ Exclude normal files from main and sub-s + .hgsubstate + large.bin + main ++ sub1/ + sub1/.hgsub + sub1/.hgsubstate + sub1/sub1 ++ sub1/sub2/ + sub1/sub2/large.bin + sub1/sub2/sub2 + +diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t +--- a/tests/test-subrepo-git.t ++++ b/tests/test-subrepo-git.t +@@ -378,6 +378,7 @@ archive subrepos + .hgsub + .hgsubstate + a ++ s/ + s/g + + $ hg -R ../tc archive -S ../lf_archive.tgz --prefix '.' \ +@@ -387,6 +388,7 @@ archive subrepos + .hgsub + .hgsubstate + a ++ s/ + s/g + + create nested repo +diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t +--- a/tests/test-subrepo-recursion.t ++++ b/tests/test-subrepo-recursion.t +@@ -443,9 +443,11 @@ Test archiving to zip file (unzip output + 10 [0-9:\- ]* .hgsub (re) + 45 [0-9:\- ]* .hgsubstate (re) + 3 [0-9:\- ]* x.txt (re) ++ 0 [0-9:\- ]* foo/ (re) + 10 [0-9:\- ]* foo/.hgsub (re) + 45 [0-9:\- ]* foo/.hgsubstate (re) + 9 [0-9:\- ]* foo/y.txt (re) ++ 0 [0-9:\- ]* foo/bar/ (re) + 9 [0-9:\- ]* foo/bar/z.txt (re) + + Test archiving a revision that references a subrepo that is not yet +@@ -591,8 +593,10 @@ Archive + subrepos uses '/' for all comp + .hg_archival.txt + .hgsub + .hgsubstate ++ foo/ + foo/.hgsub + foo/.hgsubstate ++ foo/bar/ + foo/bar/z.txt + foo/y.txt + x.txt diff -Nru mercurial-7.0.1/debian/patches/hg-sa-2026-003.patch mercurial-7.0.1/debian/patches/hg-sa-2026-003.patch --- mercurial-7.0.1/debian/patches/hg-sa-2026-003.patch 1970-01-01 00:00:00.000000000 +0000 +++ mercurial-7.0.1/debian/patches/hg-sa-2026-003.patch 2026-12-02 16:51:39.000000000 +0000 @@ -0,0 +1,95 @@ +# HG changeset patch +# User Raphaël Gomès +# Date 1796228786 -3600 +# Wed Dec 02 17:26:26 2026 +0100 +# Branch stable +# Node ID 8972e8e1a4482c0bfa8a1c71baff90697a375dbe +# Parent 98f3571f3f4485949b140ffe450ee288b743d2bb +# EXP-Topic hg-sa-2026-003-7.0 +hg-sa-2026-003: backport the update fix to Mercurial 7.0 + +A malicious manifest can pair a symlink with a path below it, for example a +`first` symlink pointing to `.hg` and a `first/hgrc` entry. Updating the +working copy audits each path before writing it, but when workers write files +in parallel, one of them can create the symlink between the audit of the path +below it and its write. The write then goes through the symlink, for example +into `.hg/hgrc`, which lets the manifest run arbitrary code. + +This patch applies on top of Mercurial 7.0.3 (a9b453aa7524). It ports the +Python part of the update fix from 12bde3c541ac, 49c84408cdaf and +6aeded39f4c3: we write all symlinks before any regular file, deepest first, +one worker batch per depth, so that no symlink can be created while a path +below it is being audited or written. On 7.0, this code lives in +`mercurial/merge.py` instead of `mercurial/merge_utils/update.py`. + +The Rust update code, the tests and the devel synchronisation they rely on +are not part of this backport. + +diff --git a/mercurial/merge.py b/mercurial/merge.py +--- a/mercurial/merge.py ++++ b/mercurial/merge.py +@@ -1659,22 +1659,50 @@ def applyupdates( + threadsafe = repo.ui.configbool( + b'experimental', b'worker.wdir-get-thread-safe' + ) +- prog = worker.worker( +- repo.ui, +- cost, +- batchget, +- (repo, mctx, wctx, wantfiledata), +- list(mresult.getactions([mergestatemod.ACTION_GET], sort=True)), +- threadsafe=threadsafe, +- hasretval=True, +- ) + getfiledata = {} +- for final, res in prog: +- if final: +- getfiledata = res ++ action_batches = [] ++ file_actions = [] ++ symlink_actions = [] ++ ++ # We need to materialize Materialize symlinks before any regular file to ++ # preventa potential race condition between auditing the path we write to ++ # and the symlink update. So we split the two kind appart. ++ for a in mresult.getactions([mergestatemod.ACTION_GET], sort=True): ++ if b'l' in a[1][0]: ++ symlink_actions.append(a) + else: +- i, item = res +- progress.increment(step=i, item=item) ++ file_actions.append(a) ++ ++ # handle the symlink first (if any) ++ if symlink_actions: ++ # we create symlink in multiple batch, deepest first. to prevent ++ # symlink to racing themselves. ++ depth_bucket = collections.defaultdict(list) ++ for a in symlink_actions: ++ depth_bucket[a[0].count(b"/")].append(a) ++ for _depth, actions in sorted(depth_bucket.items(), reverse=True): ++ action_batches.append(actions) ++ ++ # then the regular file (if any) ++ if file_actions: ++ action_batches.append(file_actions) ++ ++ for actions in action_batches: ++ prog = worker.worker( ++ repo.ui, ++ cost, ++ batchget, ++ (repo, mctx, wctx, wantfiledata), ++ actions, ++ threadsafe=threadsafe, ++ hasretval=True, ++ ) ++ for final, res in prog: ++ if final: ++ getfiledata.update(res) ++ else: ++ i, item = res ++ progress.increment(step=i, item=item) + + if b'.hgsubstate' in mresult._actionmapping[mergestatemod.ACTION_GET]: + subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) diff -Nru mercurial-7.0.1/debian/patches/hg-sa-2026-004.patch mercurial-7.0.1/debian/patches/hg-sa-2026-004.patch --- mercurial-7.0.1/debian/patches/hg-sa-2026-004.patch 1970-01-01 00:00:00.000000000 +0000 +++ mercurial-7.0.1/debian/patches/hg-sa-2026-004.patch 2026-12-02 16:16:41.000000000 +0000 @@ -0,0 +1,567 @@ +# HG changeset patch +# User Raphaël Gomès +# Date 1796224278 -3600 +# Wed Dec 02 16:11:18 2026 +0100 +# Branch stable +# Node ID abe539118807b663e55df8e324cb5323b406e057 +# Parent 98f3571f3f4485949b140ffe450ee288b743d2bb +# EXP-Topic hg-sa-2026-004-7.0 +hg-sa-2026-004: backport the fixes to Mercurial 7.0 + +Mercurial writes the source of a subrepository, read from `.hgsub`, verbatim +as a `[paths]` value in the subrepository's `.hg/hgrc`. A source containing a +line break therefore lets a malicious `.hgsub` inject arbitrary configuration, +and through it run arbitrary code, when the subrepository is cloned. `hg clone` +and `hg share` write their default path the same way. + +This patch applies on top of Mercurial 7.0.3 (a9b453aa7524). It squashes the +stable series d07ac4dbe9f2::611ad7796a61: we refuse line breaks in a +subrepository's source when reading `.hgsub` and when writing the +subrepository's hgrc, and in the default path written by `hg clone` and +`hg share`. On 7.0, the clone and share code lives in `mercurial/hg.py` +instead of `mercurial/cmd_impls/clone.py`; the checks are otherwise +identical, and so is the test output. + +Reported by ozgun kultekin. + +diff --git a/mercurial/hg.py b/mercurial/hg.py +--- a/mercurial/hg.py ++++ b/mercurial/hg.py +@@ -468,6 +468,7 @@ def postshare(sourcerepo, destrepo, defa + """ + default = defaultpath or sourcerepo.ui.config(b'paths', b'default') + if default: ++ urlutil.check_safe_for_config(default) + template = b'[paths]\ndefault = %s\n' + destrepo.vfs.write(b'hgrc', util.tonativeeol(template % default)) + if requirements.NARROW_REQUIREMENT in sourcerepo.requirements: +@@ -1060,6 +1061,7 @@ def clone( + u = urlutil.url(abspath) + u.passwd = None + defaulturl = bytes(u) ++ urlutil.check_safe_for_config(defaulturl) + destrepo.vfs.write(b'hgrc', util.tonativeeol(template % defaulturl)) + destrepo.ui.setconfig(b'paths', b'default', defaulturl, b'clone') + +diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py +--- a/mercurial/subrepo.py ++++ b/mercurial/subrepo.py +@@ -563,6 +563,9 @@ class hgsubrepo(abstractsubrepo): + + def addpathconfig(key, value): + if value: ++ if b'\n' in value or b'\r' in value: ++ msg = _(b"subrepository path contains a line break") ++ raise error.Abort(msg) + lines.append(b'%s = %s\n' % (key, value)) + self.ui.setconfig(b'paths', key, value, b'subrepo') + +diff --git a/mercurial/subrepoutil.py b/mercurial/subrepoutil.py +--- a/mercurial/subrepoutil.py ++++ b/mercurial/subrepoutil.py +@@ -171,8 +171,15 @@ def state(ctx: context.changectx, ui: ui + else: + src = remapped + +- src = remap(src) +- state[util.pconvert(path)] = (src.strip(), rev.get(path, b''), kind) ++ src = remap(src).strip() ++ # the source ends up in the subrepository's .hg/hgrc as a ++ # [paths] value: a line break would let the (untrusted) .hgsub ++ # inject arbitrary configuration, and is never valid in a path ++ if b'\n' in src or b'\r' in src: ++ msg = _(b"subrepository path contains a line break: %s") ++ msg %= path ++ raise error.Abort(msg) ++ state[util.pconvert(path)] = (src, rev.get(path, b''), kind) + + return state + +diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py +--- a/mercurial/utils/urlutil.py ++++ b/mercurial/utils/urlutil.py +@@ -444,6 +444,22 @@ def checksafessh(path: bytes) -> None: + ) + + ++def check_safe_for_config(path: bytes) -> None: ++ """check that a path / url can be written as a config value (SEC) ++ ++ Code creating a repository records where it comes from in the `[paths]` ++ section of its configuration, writing the path as is. A line break in it ++ would end the value there, and the rest of the path would be read as ++ configuration of its own. ++ ++ Raises an error.Abort when the path contains a line break. ++ """ ++ if b'\n' in path or b'\r' in path: ++ msg = _(b'path contains a line break: %r') ++ msg %= pycompat.bytestr(path) ++ raise error.Abort(msg) ++ ++ + def hidepassword(u: bytes) -> bytes: + '''hide user credential in a url string''' + u = url(u) +diff --git a/tests/test-hg-sa-2026-004-subrepo-hgsub-config-injection.t b/tests/test-hg-sa-2026-004-subrepo-hgsub-config-injection.t +new file mode 100644 +--- /dev/null ++++ b/tests/test-hg-sa-2026-004-subrepo-hgsub-config-injection.t +@@ -0,0 +1,457 @@ ++========================================================================== ++Test potential config injestion through malformated hgsub (HG-SA-2026-004) ++========================================================================== ++ ++ ++A subrepository source read from an untrusted .hgsub must not be able to inject ++configuration into the .hg/hgrc that Mercurial writes when it creates the ++subrepository on demand ++ ++Such creation may happens not only during update, but through other command too ++(for example while serving 'hg cat' in a bare clone). ++ ++CURRENTLY: Some of this operation are currently allowing arbitrary code execution. ++ ++In the same way, a `hg clone` or `hg share` command from a path containing new ++line should not be able to inject configuration in the resulting repository. ++ ++CURRENTLY hg clone and hg share allow for that. ++ ++Setup ++===== ++ ++ $ hg init sub ++ $ echo s > sub/s ++ $ hg -R sub commit -qAm s ++ $ hg init src ++ $ cd src ++ $ echo hi > README ++ $ hg commit -qAm init ++ ++The source has indented continuation lines, which the config parser used for ++.hgsub folds into the value with embedded newlines. ++ ++(Create the commit with 'import --bypass' so that no subrepository is ever ++opened while building it.) ++ ++ $ cat > ../evil.patch < # HG changeset patch ++ > # User Rataxes ++ > # Date 1796086439 -3600 ++ > # Parent $(hg log -r tip -T '{node}\n') ++ > add subrepo ++ > ++ > diff --git a/.hgsub b/.hgsub ++ > new file mode 100644 ++ > --- /dev/null ++ > +++ b/.hgsub ++ > @@ -0,0 +1,5 @@ ++ > +sub = /nonexistent ++ > + [extensions] ++ > + logtoprocess = ++ > + [logtoprocess] ++ > + extension = touch \$TESTTMP/pwned ++ > diff --git a/.hgsubstate b/.hgsubstate ++ > new file mode 100644 ++ > --- /dev/null ++ > +++ b/.hgsubstate ++ > @@ -0,0 +1,1 @@ ++ > +$(hg -R ../sub log -r tip -T '{node}') sub ++ > EOF ++ $ hg import -q --bypass ../evil.patch ++ $ cd .. ++ ++ ++Creating the repository through `hg update` ++=========================================== ++ ++updating the clone create the subrepository ++ ++ $ hg clone -q -U src updated ++ $ cd updated ++ ++First update ++------------ ++ ++ $ hg update #1 ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after update #1) ++ ++ $ ls -1 ++ README ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after update #1) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++Second update ++------------- ++ ++ $ hg update #2 ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after update #2) ++ $ ls -1 ++ README ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after update #2) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++ $ cd .. ++ ++ ++Creating the repository through `hg cat --rev X` ++================================================ ++ ++Read commands in a bare clone create the subrepository on demand. ++ ++ $ hg clone -q -U src bare ++ $ cd bare ++ ++First cat use ++------------- ++ ++ $ hg cat -r tip -- absent-file #1 ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Did the sub repo appeared? (after cat #1) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after cat #1) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++Second cat use ++-------------- ++ ++ $ hg cat -r tip -- absent-file #2 ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after cat #2) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after cat #2) ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++ $ cd .. ++ ++ ++ ++Creating the repository through `hg archive --rev X` ++==================================================== ++ ++ $ hg clone -q -U src bare-archive-plain ++ $ cd bare-archive-plain ++ ++First archive run ++----------------- ++ ++ $ hg archive -r tip ../out #1 ++ ++Is sub repo here? (after archive #1) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after archive #1) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++Second archive run ++------------------ ++ ++ $ hg archive -r tip ../out #2 ++ ++Is sub repo here? (after archive #2) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after archive #2) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++ $ cd .. ++ ++ ++Creating the repository through `hg archive -S --rev X` ++======================================================= ++ ++ $ hg clone -q -U src bare-archive-S ++ $ cd bare-archive-S ++ ++First archive run ++----------------- ++ ++ $ hg archive -S -r tip ../out #1 ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after archive -S #1) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after archive -S #1) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++Second archive run ++------------------ ++ ++ $ hg archive -S -r tip ../out #2 ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after archive -S #2) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after archive -S #2) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++ $ cd .. ++ ++ ++Creating the repository through `hg log -p --rev X` ++=================================================== ++ ++ $ hg clone -q -U src bare-log-p ++ $ cd bare-log-p ++ ++First log use ++------------- ++ ++ $ hg log -p -r tip -T '{desc}\n' #1 ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after log -p #1) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after log -p #1) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++Second log use ++-------------- ++ ++ $ hg log -p -r tip -T '{desc}\n' #2 ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after log -p #2) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after log -p #2) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++ $ cd .. ++ ++ ++Creating the repository through `hg diff -c X` ++============================================== ++ ++ $ hg clone -q -U src bare-diff-c ++ $ cd bare-diff-c ++ ++First diff use ++-------------- ++ ++ $ hg diff -c tip #1 ++ diff -r 013ee79f985c -r 9cecc527812f .hgsub (known-bad-output !) ++ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 (known-bad-output !) ++ +++ b/.hgsub Tue Dec 01 01:53:59 2026 +0100 (known-bad-output !) ++ @@ -0,0 +1,5 @@ (known-bad-output !) ++ +sub = /nonexistent (known-bad-output !) ++ + [extensions] (known-bad-output !) ++ + logtoprocess = (known-bad-output !) ++ + [logtoprocess] (known-bad-output !) ++ + extension = touch $TESTTMP/pwned (known-bad-output !) ++ diff -r 013ee79f985c -r 9cecc527812f .hgsubstate (known-bad-output !) ++ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 (known-bad-output !) ++ +++ b/.hgsubstate Tue Dec 01 01:53:59 2026 +0100 (known-bad-output !) ++ @@ -0,0 +1,1 @@ (known-bad-output !) ++ +e9a815d3240a5f63c83a9cb07029582bc8c980c5 sub (known-bad-output !) ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after diff -c #1) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after diff -c #1) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++Second diff use ++--------------- ++ ++ $ hg diff -c tip #2 ++ diff -r 013ee79f985c -r 9cecc527812f .hgsub (known-bad-output !) ++ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 (known-bad-output !) ++ +++ b/.hgsub Tue Dec 01 01:53:59 2026 +0100 (known-bad-output !) ++ @@ -0,0 +1,5 @@ (known-bad-output !) ++ +sub = /nonexistent (known-bad-output !) ++ + [extensions] (known-bad-output !) ++ + logtoprocess = (known-bad-output !) ++ + [logtoprocess] (known-bad-output !) ++ + extension = touch $TESTTMP/pwned (known-bad-output !) ++ diff -r 013ee79f985c -r 9cecc527812f .hgsubstate (known-bad-output !) ++ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 (known-bad-output !) ++ +++ b/.hgsubstate Tue Dec 01 01:53:59 2026 +0100 (known-bad-output !) ++ @@ -0,0 +1,1 @@ (known-bad-output !) ++ +e9a815d3240a5f63c83a9cb07029582bc8c980c5 sub (known-bad-output !) ++ abort: subrepository path contains a line break: sub ++ [255] ++ ++Is sub repo here? (after diff -c #2) ++ ++ $ ls -1 ++ $ hg -R sub root ++ abort: repository sub not found ++ [255] ++ $ test -f sub/.hg/hgrc && cat sub/.hg/hgrc ++ [1] ++ ++Did we run arbitrary code? (after diff -c #2) ++ ++ $ test -f $TESTTMP/pwned && echo "Arbitrary code execution!" ++ [1] ++ $ rm -f $TESTTMP/pwned ++ ++ $ cd .. ++ ++#if eol-in-paths ++ ++Writing the default path through `hg clone` ++=========================================== ++ ++This is not subrepository related. Pure `hg clone` could achieve this as part ++of HG-SA-2026-004, but only with a local path, so with limited effect. ++ ++ $ evil_source="`printf 'celeste\n[ui]\nusername = rataxes'`" ++ $ hg init "$evil_source" ++ $ hg clone "$evil_source" pom ++ abort: path contains a line break: '$TESTTMP/celeste\n[ui]\nusername = rataxes' ++ [255] ++ ++Did we inject configuration? (after clone) ++ ++ $ hg -R pom config ui.username ++ [1] ++ ++#endif ++ ++ ++Writing the default path through `hg share` ++=========================================== ++ ++This is not subrepository related. Pure `hg share` sharing a repository with ++malformated path. ++ ++(arguably, if the source repo was able to inject the malformated config, it ++might be able to inject more, but this is still a different issue that could be ++exploited further) ++ ++ $ hg init flore ++ $ cat >> flore/.hg/hgrc << EOF ++ > [paths] ++ > default = /nonexistent ++ > [ui] ++ > username = rataxes ++ > EOF ++ $ hg share --config extensions.share= flore alexandre ++ abort: path contains a line break: '/nonexistent\n[ui]\nusername = rataxes' ++ [255] ++ ++Did we inject configuration? (after share) ++ ++ $ hg -R alexandre config ui.username ++ [1] diff -Nru mercurial-7.0.1/debian/patches/series mercurial-7.0.1/debian/patches/series --- mercurial-7.0.1/debian/patches/series 2025-04-18 15:28:42.000000000 +0000 +++ mercurial-7.0.1/debian/patches/series 2026-12-02 16:52:36.000000000 +0000 @@ -5,3 +5,9 @@ test-hghave-testrepo.patch test_copies_chain_merge_slow.patch pyproject-version-file.patch +zstd-policy.patch +deb_specific__system-zstandard.patch +test-hghave-zstd.patch +hg-sa-2026-001.patch +hg-sa-2026-003.patch +hg-sa-2026-004.patch diff -Nru mercurial-7.0.1/debian/patches/test-hghave-zstd.patch mercurial-7.0.1/debian/patches/test-hghave-zstd.patch --- mercurial-7.0.1/debian/patches/test-hghave-zstd.patch 1970-01-01 00:00:00.000000000 +0000 +++ mercurial-7.0.1/debian/patches/test-hghave-zstd.patch 2026-12-01 08:31:23.000000000 +0000 @@ -0,0 +1,29 @@ +From: Julien Cristau +Subject: hghave: detect zstd through hg debuginstall + +Checking for mercurial.zstd misses the system zstandard module that +mercurial.policy can fall back to. Use the check from upstream 7.2. + +Origin: backport, upstream 7.2 +Forwarded: not-needed +--- +--- a/tests/hghave.py ++++ b/tests/hghave.py +@@ -946,13 +946,10 @@ def unzip_understands_symlinks(): + + @check("zstd", "zstd Python module available") + def has_zstd(): +- try: +- import mercurial.zstd +- +- del mercurial.zstd +- return True +- except ImportError: +- return False ++ return matchoutput( ++ 'hg debuginstall', ++ br'checking available compression engines.*zstd', ++ ) + + + @check("devfull", "/dev/full special file") diff -Nru mercurial-7.0.1/debian/patches/zstd-policy.patch mercurial-7.0.1/debian/patches/zstd-policy.patch --- mercurial-7.0.1/debian/patches/zstd-policy.patch 1970-01-01 00:00:00.000000000 +0000 +++ mercurial-7.0.1/debian/patches/zstd-policy.patch 2026-12-01 08:30:09.000000000 +0000 @@ -0,0 +1,229 @@ +# HG changeset patch +# User Pierre-Yves David +# Date 1762165621 -3600 +# Mon Nov 03 11:27:01 2025 +0100 +# Node ID c872de9be9a73b147956c446f084c4244fe2995e +# Parent eb93500fcb432d1d22c443662ca6bda7466d0ff0 +zstd: fallback on system package of the vendored module is not available + +This provide to advantage: +- a pure install now has a change to read a zstd repository, +- distribution can easily "unvendor" the zstandard module. + +[backported to 7.0.1 by Julien Cristau: drop contrib/check-code.py, + contrib/heptapod-ci.yml and tests/test-check-module-imports.t changes, + adjust context, use grep -c instead of the unavailable f --line-count] +Origin: upstream, hg changeset c872de9be9a73b147956c446f084c4244fe2995e + +diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py +--- a/mercurial/chgserver.py ++++ b/mercurial/chgserver.py +@@ -97,7 +97,7 @@ _configsectionitems = [ + _envre = re.compile( + br'''\A(?: + CHGHG +- |HG(?:DEMANDIMPORT|EMITWARNINGS|MODULEPOLICY|PROF|RCPATH)? ++ |HG(?:DEMANDIMPORT|EMITWARNINGS|(MODULE|ZSTD)POLICY|PROF|RCPATH)? + |HG(?:ENCODING|PLAIN).* + |LANG(?:UAGE)? + |LC_.* +diff --git a/mercurial/helptext/environment.txt b/mercurial/helptext/environment.txt +--- a/mercurial/helptext/environment.txt ++++ b/mercurial/helptext/environment.txt +@@ -122,3 +122,19 @@ EDITOR + PYTHONPATH + This is used by Python to find imported modules and may need to be + set appropriately if this Mercurial is not installed system-wide. ++ ++ ++HGZSTDPOLICY ++ Control which zstd implementation will be used for the Python code. This is ++ a list of options in priority order. ++ ++ - vendored: use the pinned version of python-zstandard shipped in Mercurial ++ - system: use a possibly installed "zstandard" python package ++ - none: don't use zstd (ommiting this will raise an error if the above ++ fails) ++ ++ Default value is "vendored,system,none" ++ ++ This variable might be deprecated in the future depending on how zstd wrapper ++ library and they integration in Mercurial evolves. This config has no ++ effect on the Rust code. +diff --git a/mercurial/policy.py b/mercurial/policy.py +--- a/mercurial/policy.py ++++ b/mercurial/policy.py +@@ -33,6 +33,12 @@ if typing.TYPE_CHECKING: + # run without recompiling the C extensions. This will be overridden by + # __modulepolicy__ generated by setup.py. + policy: bytes = b'allow' ++ ++_ZP_VENDOR = b'vendored' ++_ZP_SYSTEM = b'system' ++_ZP_NONE = b'none' ++ ++zstd_policy: list[bytes] = [_ZP_VENDOR, _ZP_SYSTEM, _ZP_NONE] + _packageprefs: Dict[bytes, Tuple[Optional[str], Optional[str]]] = { + # policy: (versioned package, pure package) + b'c': ('cext', None), +@@ -63,6 +69,10 @@ if '__pypy__' in sys.builtin_module_names: + if os.environ.get('HGMODULEPOLICY'): # ignore None and Empty + policy: bytes = os.environ['HGMODULEPOLICY'].encode('utf-8') + ++# Environment variable can always force settings. ++if env_zstd := os.environ.get('HGZSTDPOLICY'): # ignore None and Empty ++ zstd_policy = [x.strip() for x in env_zstd.encode('utf-8').split(b',')] ++ + + def _importfrom(pkgname: str, modname: str): + # from . import (where . is looked through this module) +@@ -162,3 +172,46 @@ def importrust( + if _isrustpermissive(): + return default + raise ImportError("Cannot import name %s" % member) ++ ++ ++def _get_zstd(_catch=True): ++ """return a zstd module according to policy or None ++ ++ Can raise ImportError if no module is available and "none" is not an ++ available policy. ++ """ ++ if not zstd_policy: ++ raise RuntimeError("empty zstd policy should not happen") ++ for p in zstd_policy: ++ if p not in [_ZP_VENDOR, _ZP_SYSTEM, _ZP_NONE]: ++ raise RuntimeError('invalid HG_ZSTD_POLICY %r' % policy) ++ try: ++ if p == _ZP_VENDOR: ++ from . import zstd # pytype: disable=import-error ++ elif p == _ZP_SYSTEM: ++ import zstandard as zstd # pytype: disable=import-error ++ elif p == _ZP_NONE: ++ zstd = None ++ break # found something ! ++ else: ++ assert False, "unreachable: %r" % p ++ if zstd is not None: ++ # Force delayed import. ++ zstd.__version__ ++ break # found something ! ++ except ImportError: ++ if not _catch: ++ raise ++ else: # found nothing ++ if not _catch: ++ raise RuntimeError("impossible infinite loop") ++ _get_zstd(_catch=False) ++ ++ # replace oneself with the result ++ # (importing functools in such a low level module seems wrong) ++ global get_zstd ++ get_zstd = lambda: zstd ++ return zstd ++ ++ ++get_zstd = _get_zstd +diff --git a/mercurial/utils/compression.py b/mercurial/utils/compression.py +--- a/mercurial/utils/compression.py ++++ b/mercurial/utils/compression.py +@@ -12,6 +12,7 @@ import zlib + from .. import ( + error, + i18n, ++ policy, + pycompat, + ) + from . import stringutil +@@ -643,14 +644,7 @@ class _zstdengine(compressionengine): + def _module(self): + # Not all installs have the zstd module available. So defer importing + # until first access. +- try: +- from .. import zstd # pytype: disable=import-error +- +- # Force delayed import. +- zstd.__version__ +- return zstd +- except ImportError: +- return None ++ return policy.get_zstd() + + def available(self): + return bool(self._module) +diff --git a/mercurial/wireprotoframing.py b/mercurial/wireprotoframing.py +--- a/mercurial/wireprotoframing.py ++++ b/mercurial/wireprotoframing.py +@@ -32,6 +32,7 @@ if typing.TYPE_CHECKING: + from . import ( + encoding, + error, ++ policy, + pycompat, + util, + wireprototypes, +@@ -831,8 +832,8 @@ class zlibdecoder(Decoder): + + class zstdbaseencoder(Encoder): + def __init__(self, level: int) -> None: +- from . import zstd # pytype: disable=import-error +- ++ zstd = policy.get_zstd() ++ assert zstd is not None + self._zstd = zstd + cctx = zstd.ZstdCompressor(level=level) + self._compressor = cctx.compressobj() +@@ -859,7 +860,8 @@ class zstd8mbencoder(zstdbaseencoder): + + class zstdbasedecoder(Decoder): + def __init__(self, maxwindowsize: int) -> None: +- from . import zstd # pytype: disable=import-error ++ zstd = policy.get_zstd() ++ assert zstd is not None + + dctx = zstd.ZstdDecompressor(max_window_size=maxwindowsize) + self._decompressor = dctx.decompressobj() +@@ -894,15 +896,10 @@ def populatestreamencoders() -> None: + if STREAM_ENCODERS: + return + +- try: +- from . import zstd # pytype: disable=import-error +- +- zstd.__version__ +- except ImportError: +- zstd = None ++ zstd = policy.get_zstd() + + # zstandard is fastest and is preferred. +- if zstd: ++ if zstd is not None: + STREAM_ENCODERS[b'zstd-8mb'] = (zstd8mbencoder, zstd8mbdecoder) + STREAM_ENCODERS_ORDER.append(b'zstd-8mb') + +diff --git a/tests/test-repo-compengines.t b/tests/test-repo-compengines.t +--- a/tests/test-repo-compengines.t ++++ b/tests/test-repo-compengines.t +@@ -1,3 +1,22 @@ ++Check control over zstd import ++ ++#if zstd ++ $ hg debuginstall | grep "checking available compression engines" | grep -c zstd ++ 2 ++ ++ $ HGZSTDPOLICY=none hg debuginstall | grep "checking available compression engines" | grep -c zstd ++ 0 ++ [1] ++#else ++ $ hg debuginstall | grep "checking available compression engines" | grep -c zstd ++ 0 ++ [1] ++ $ HGZSTDPOLICY=vendored hg debuginstall >/dev/null ++ abort: cannot import name 'zstd' from 'mercurial' (*/mercurial/__init__.py) (glob) ++ [255] ++#endif ++ ++ + A new repository uses zlib storage, which doesn't need a requirement + + $ cat << EOF >> $HGRCPATH diff -Nru mercurial-7.0.1/debian/rules mercurial-7.0.1/debian/rules --- mercurial-7.0.1/debian/rules 2025-04-18 15:28:42.000000000 +0000 +++ mercurial-7.0.1/debian/rules 2026-12-02 16:32:30.000000000 +0000 @@ -46,6 +46,12 @@ --blacklist $(CURDIR)/debian/mercurial.test_blacklist_riscv64 endif +# binary test bundles from security fixes, which dpkg-source can't patch in +TEST_BUNDLES := $(notdir $(wildcard debian/tests-bundles/*)) + +execute_before_dh_auto_test: + cp $(addprefix debian/tests-bundles/,$(TEST_BUNDLES)) tests/bundles/ + override_dh_auto_test: ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) http_proxy='' $(MAKE) tests PYTHON=python3 TESTFLAGS="$(test_flags)" PYTHONPATH=$(BUILD_DIR) @@ -85,6 +91,7 @@ dh_auto_clean $(MAKE) clean $(RM) -rv tmp/ + $(RM) $(addprefix tests/bundles/,$(TEST_BUNDLES)) mercurial/__version__.py: @echo "$@ is missing (you probably call 'make clean' directly)." diff -Nru mercurial-7.0.1/debian/source/include-binaries mercurial-7.0.1/debian/source/include-binaries --- mercurial-7.0.1/debian/source/include-binaries 1970-01-01 00:00:00.000000000 +0000 +++ mercurial-7.0.1/debian/source/include-binaries 2026-12-02 16:32:15.000000000 +0000 @@ -0,0 +1,18 @@ +debian/tests-bundles/base-bundle.hg +debian/tests-bundles/evil-bundle.hg +debian/tests-bundles/evil-repo-compzstd.tar +debian/tests-bundles/evil-repo-general-delta.tar +debian/tests-bundles/evil-repo-prev-delta.tar +debian/tests-bundles/evil-repo-sparse-delta.tar +debian/tests-bundles/evil-repo-storeless.tar +debian/tests-bundles/evil-stream-v1-compzstd.hg +debian/tests-bundles/evil-stream-v1-general-delta.hg +debian/tests-bundles/evil-stream-v1-prev-delta.hg +debian/tests-bundles/evil-stream-v1-sparse-delta.hg +debian/tests-bundles/evil-stream-v1-storeless.hg +debian/tests-bundles/evil-stream-v2-compzstd.hg +debian/tests-bundles/evil-stream-v2-general-delta.hg +debian/tests-bundles/evil-stream-v2-prev-delta.hg +debian/tests-bundles/evil-stream-v2-sparse-delta.hg +debian/tests-bundles/evil-stream-v2-storeless.hg +debian/tests-bundles/tampered.tar Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/base-bundle.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/base-bundle.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-bundle.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-bundle.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-repo-compzstd.tar and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-compzstd.tar differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-repo-general-delta.tar and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-general-delta.tar differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-repo-prev-delta.tar and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-prev-delta.tar differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-repo-sparse-delta.tar and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-sparse-delta.tar differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-repo-storeless.tar and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-repo-storeless.tar differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-compzstd.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-compzstd.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-general-delta.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-general-delta.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-prev-delta.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-prev-delta.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-sparse-delta.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-sparse-delta.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-storeless.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v1-storeless.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-compzstd.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-compzstd.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-general-delta.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-general-delta.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-prev-delta.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-prev-delta.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-sparse-delta.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-sparse-delta.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-storeless.hg and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/evil-stream-v2-storeless.hg differ Binary files /srv/release.debian.org/tmp/0xfqagmh9d/mercurial-7.0.1/debian/tests-bundles/tampered.tar and /srv/release.debian.org/tmp/Ag6fq2hzqv/mercurial-7.0.1/debian/tests-bundles/tampered.tar differ