From f007ede7ad0684080e2dc9a97a1296b88f95e9fd Mon Sep 17 00:00:00 2001 From: Blue Date: Wed, 15 Jan 2025 12:44:51 -0800 Subject: [PATCH] Add logic to warn if tar compression format is unknown, or not supported by WSL1 (#12466) --- distributions/validate-modern.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/distributions/validate-modern.py b/distributions/validate-modern.py index e9b2c5b2..6b3f4b84 100644 --- a/distributions/validate-modern.py +++ b/distributions/validate-modern.py @@ -18,6 +18,8 @@ X64_ELF_MAGIC = re.compile('^ELF 64-bit.* x86-64, version 1') ARM64_ELF_MAGIC = re.compile('^ELF 64-bit.* ARM aarch64, version 1') +KNOWN_TAR_FORMATS = {'^XZ compressed data.*': False, '^gzip compressed data.*': True} + DISCOURAGED_SYSTEM_UNITS = ['systemd-resolved.service', 'systemd-networkd.service', 'systemd-tmpfiles-setup.service', @@ -406,6 +408,7 @@ def read_url(flavor: str, name: str, url: dict, elf_magic): if not url['Url'].endswith('.wsl'): warning(flavor, name, f'Url does not point to a .wsl file: {url["Url"]}') + tar_format = None if url['Url'].startswith('file://'): with open(url['Url'].replace('file:///', '').replace('file://', ''), 'rb') as fd: while True: @@ -415,6 +418,9 @@ def read_url(flavor: str, name: str, url: dict, elf_magic): hash.update(e) + if tar_format is None: + tar_format = MAGIC.from_buffer(e) + fd.seek(0, 0) read_tar(flavor, name, fd, elf_magic) else: @@ -426,6 +432,9 @@ def read_url(flavor: str, name: str, url: dict, elf_magic): file.write(e) hash.update(e) + if tar_format is None: + tar_format = MAGIC.from_buffer(e) + file.seek(0, 0) read_tar(flavor, name, file, elf_magic) @@ -443,7 +452,11 @@ def read_url(flavor: str, name: str, url: dict, elf_magic): else: click.secho(f'Hash for {url["Url"]} matches ({expected_sha})', fg='green') - + known_format = next((value for key, value in KNOWN_TAR_FORMATS.items() if re.match(key, tar_format)), None) + if known_format is None: + error(flavor, name, f'Unknown tar format: {tar_format}') + elif not known_format: + warning(flavor, name, f'Tar format not supported by WSL1: {tar_format}') def error(flavor: str, distribution: str, message: str): global errors