diff mercurial/exchange.py @ 30889:ffed3bf5cd4c stable

exchange: reject new compression engines for v1 bundles (issue5506) Version 1 bundles only support a fixed set of compression engines. Before this change, we would accept any compression engine for v1 bundles, even those that may not work on v1. This could lead to an error. We define a fixed set of compression engines known to work with v1 bundles and we add checking to ensure a newer engine (like zstd) won't work with v1 bundles. I also took the liberty of adding test coverage for unknown compression names because I noticed we didn't have coverage of it before.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 16 Mar 2017 12:23:56 -0700
parents d70971a3ae80
children 10c0ee338535
line wrap: on
line diff
--- a/mercurial/exchange.py	Tue Mar 07 13:24:24 2017 -0500
+++ b/mercurial/exchange.py	Thu Mar 16 12:23:56 2017 -0700
@@ -44,6 +44,9 @@
                          'bundle2': '02', #legacy
                         }
 
+# Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE.
+_bundlespecv1compengines = set(['gzip', 'bzip2', 'none'])
+
 def parsebundlespec(repo, spec, strict=True, externalnames=False):
     """Parse a bundle string specification into parts.
 
@@ -139,6 +142,12 @@
             raise error.UnsupportedBundleSpecification(
                     _('%s is not a recognized bundle specification') % spec)
 
+    # Bundle version 1 only supports a known set of compression engines.
+    if version == 'v1' and compression not in _bundlespecv1compengines:
+        raise error.UnsupportedBundleSpecification(
+            _('compression engine %s is not supported on v1 bundles') %
+            compression)
+
     # The specification for packed1 can optionally declare the data formats
     # required to apply it. If we see this metadata, compare against what the
     # repo supports and error if the bundle isn't compatible.