Skip to content
Snippets Groups Projects
Commit 778fa799 authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Add a special-case to squshfs image extraction to not fail if we are not root....

Add a special-case to squshfs image extraction to not fail if we are not root. (Closes: Debian:#991059)

Don't treat a failure to extract all entries from squashfs images as a failure that requires falling back to xxd(1) --
parent 80df0f6d
No related merge requests found
Pipeline #276269 failed
......@@ -35,7 +35,7 @@ from .device import Device
from .symlink import Symlink
from .directory import Directory
from .utils.archive import Archive, ArchiveMember
from .utils.command import Command, our_check_output
from .utils.command import Command
logger = logging.getLogger(__name__)
......@@ -260,20 +260,47 @@ class SquashfsContainer(Archive):
logger.debug("Extracting %s to %s", self.source.path, self._temp_dir)
output = our_check_output(
(
"unsquashfs",
"-n",
"-f",
"-no",
"-li",
"-d",
".",
os.path.abspath(self.source.path),
),
cmd = (
"unsquashfs",
"-n",
"-f",
"-no",
"-li",
"-d",
".",
os.path.abspath(self.source.path),
)
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=self._temp_dir,
)
output, stderr = p.communicate()
if p.returncode != 0:
# unsquashfs(1) exits with 1 (with a suitable logging messages that
# we can check for) if it could not extract, for example, character
# devices that require superuser privileges. In this case, don't
# treat this as a failure that requires reverting to xxd(1), but do
# let the user know via a comment.
if (
p.returncode == 1
and b"because you're not superuser" in stderr
and b"\n\ncreated " in output
):
logger.debug("Ignoring unsquashfs return code")
self.source.add_comment(
"Differences may be incomplete: {}".format(
stderr.decode("utf-8")
)
)
else:
raise subprocess.CalledProcessError(
p.returncode, cmd, output, stderr
)
output = iter(output.decode("utf-8").rstrip("\n").split("\n"))
......
......@@ -2,7 +2,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2015 Jérémy Bobbio <lunar@debian.org>
# Copyright © 2015-2017, 2019-2020 Chris Lamb <lamby@debian.org>
# Copyright © 2015-2017, 2019-2021 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -22,7 +22,7 @@ import subprocess
from diffoscope.comparators.squashfs import SquashfsFile
from ..utils.data import load_fixture, get_data
from ..utils.data import load_fixture, assert_diff
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.nonexisting import assert_non_existing
......@@ -63,25 +63,38 @@ def differences(squashfs1, squashfs2):
@skip_unless_tool_is_at_least("unsquashfs", unsquashfs_version, "4.4")
def test_superblock(differences):
expected_diff = get_data("squashfs_superblock_expected_diff")
assert differences[0].unified_diff == expected_diff
assert_diff(differences[0], "squashfs_superblock_expected_diff")
@skip_unless_tools_exist("unsquashfs")
def test_symlink(differences):
assert differences[2].comment == "symlink"
expected_diff = get_data("symlink_expected_diff")
assert differences[2].unified_diff == expected_diff
assert_diff(differences[2], "symlink_expected_diff")
@skip_unless_tools_exist("unsquashfs")
def test_compressed_files(differences):
assert differences[3].source1 == "/text"
assert differences[3].source2 == "/text"
expected_diff = get_data("text_ascii_expected_diff")
assert differences[3].unified_diff == expected_diff
assert_diff(differences[3], "text_ascii_expected_diff")
@skip_unless_tools_exist("unsquashfs")
def test_compare_non_existing(monkeypatch, squashfs1):
assert_non_existing(monkeypatch, squashfs1)
# Test things that require root
squashfs1_root = load_fixture("test1_root.squashfs")
squashfs2_root = load_fixture("test2_root.squashfs")
@pytest.fixture
def differences_root(squashfs1_root, squashfs2_root):
return squashfs1_root.compare(squashfs2_root).details
@skip_unless_tools_exist("unsquashfs")
def test_symlink_root(differences_root):
assert_diff(differences_root[1], "squashfs_root_expected_diff")
@@ -1,7 +1,7 @@
Parallel unsquashfs: Using 8 processors
3 inodes (3 blocks) to write
-drwxr-xr-x lamby/lamby 51 2015-06-24 14:47
-lrwxrwxrwx lamby/lamby 6 2015-06-24 14:47 /link -> broken
+drwxr-xr-x lamby/lamby 51 2015-06-24 14:50
+lrwxrwxrwx lamby/lamby 13 2015-06-24 14:50 /link -> really-broken
crw-r--r-- root/root 1, 3 2015-06-24 14:47 /null
--rw-r--r-- lamby/lamby 446 2015-06-24 14:49 /text
+-rw-r--r-- lamby/lamby 671 2015-06-24 14:49 /text
File added
File added
......@@ -135,6 +135,7 @@ ALLOWED_TEST_FILES = {
"test1.rpm",
"test1.sqlite3",
"test1.squashfs",
"test1_root.squashfs",
"test1.tar",
"test1.xml",
"test1.xsb",
......@@ -195,6 +196,7 @@ ALLOWED_TEST_FILES = {
"test2.rpm",
"test2.sqlite3",
"test2.squashfs",
"test2_root.squashfs",
"test2.tar",
"test2.xml",
"test2.xsb",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment