From 80e07cb7f40ab4654bcd51d815e337b8963fdcd2 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Thu, 12 Nov 2026 00:48:45 +0000 Subject: [PATCH] tools: the chroot extractors say build.prop can't be read, not that there is none When the copy of the vendor partition's build.prop failed (a full work directory, say: debugfs then prints "No space left on device", exits 0 and leaves an empty file), extract-vendor-chroot and extract-fingerprint-vendor said "vendor.img has no build.prop" although the file was in the image. They now say "build.prop can't be read from vendor.img", as extract-vendor-firmware does since #663, which is true whether the file is missing, empty or not copied. Unlike that tool they offer no override: -f skips only the device checks, so the message promises none, and the run still stops. tests/chroot-extractors is new (neither tool had a test): stand-ins for unzip and debugfs fail the copy as real debugfs does on a full disk, and each tool must say the new words. With main's tools both checks fail. Tested: the new test, tests/all and tools/pr-check origin/main, and both tools on a real ext4 vendor image holding build.prop, with the host's debugfs and the work directory on a full tmpfs. Not tested: a real factory image, and EROFS images, which both tools refuse before this line. Co-Authored-By: Claude Opus 5.5 --- tests/all | 5 ++- tests/chroot-extractors | 68 ++++++++++++++++++++++++++++++++ tools/extract-fingerprint-vendor | 2 +- tools/extract-vendor-chroot | 2 +- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100755 tests/chroot-extractors diff --git a/tests/all b/tests/all index cc523554f..31fcdaf5b 100755 --- a/tests/all +++ b/tests/all @@ -25,7 +25,8 @@ # against stand-ins for docker and repo, tools/repo-publish --from-main's # copy of the prebuilt binaries into a fixture's publish tree, # tools/repo-publish's staging, tools/extract-vendor-firmware's output -# generations (made-up files, no factory image), the callers of +# generations (made-up files, no factory image), the two chroot +# extractors' message when build.prop can't be read, the callers of # tools/alpine-fetch.py stopping when it fails, and its dependency # resolution against synthetic indexes, and the tools' --help from their # header comments (tools/lib/usage.sh). @@ -78,3 +79,5 @@ tests/module-load-once # don't meet in the same line echo "# tests/factory-index" # the build index of Google's factory images, against a made-up zip tests/factory-index +echo "# tests/chroot-extractors" +tests/chroot-extractors diff --git a/tests/chroot-extractors b/tests/chroot-extractors new file mode 100755 index 000000000..628819495 --- /dev/null +++ b/tests/chroot-extractors @@ -0,0 +1,68 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Tests for tools/extract-vendor-chroot and tools/extract-fingerprint-vendor +# with made-up images (no factory image, no Google files): small files with +# the ext4 magic stand in for vendor.img and system.img in an image zip, a +# stand-in unzip reads it with Python's zipfile, and a stand-in debugfs +# fails the copy of build.prop as real debugfs does on a full work +# directory (an error message, an empty file, exit 0). Checked: each tool +# then says build.prop can't be read, not that the image has none. +# XVC=path and XFP=path run other copies of the tools (a negative control). +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +XVC=$(realpath -- "${XVC:-tools/extract-vendor-chroot}") +XFP=$(realpath -- "${XFP:-tools/extract-fingerprint-vendor}") +failed=0 +fail() { printf 'not ok - %s\n' "$1" >&2; failed=$((failed + 1)); } +pass() { printf 'ok - %s\n' "$1"; } +t=$(mktemp -d) +trap 'rm -rf "$t"' EXIT + +mkdir -p "$t/bin" +cat > "$t/bin/unzip" <<'EOF' +#!/bin/bash +# unzip -Z1 ZIP (list) or unzip -p ZIP MEMBER (to stdout) +exec python3 -I -c ' +import sys, zipfile +with zipfile.ZipFile(sys.argv[2]) as z: + if sys.argv[1] == "-Z1": + print("\n".join(z.namelist())) + else: + sys.stdout.buffer.write(z.read(sys.argv[3])) +' "$@" +EOF +cat > "$t/bin/debugfs" <<'EOF' +#!/bin/bash +# debugfs -R "dump /build.prop OUT" IMG on a full disk: real debugfs's +# messages, an empty OUT, exit 0 +read -r _ _ out <<<"$2" +out=${out#\"}; out=${out%\"}; out=${out//\"\"/\"} # debugfs's quoting +: > "$out" +echo "debugfs 1.47.2 (stand-in)" >&2 +echo "dump: No space left on device while writing file" >&2 +exit 0 +EOF +chmod +x "$t/bin/unzip" "$t/bin/debugfs" + +head -c 4096 /dev/zero > "$t/ext4.img" +printf '\x53\xef' | dd of="$t/ext4.img" bs=1 seek=1080 conv=notrunc status=none +python3 -I -c ' +import sys, zipfile +with zipfile.ZipFile(sys.argv[1], "w") as z: + for p in ("vendor.img", "system.img"): + z.write(sys.argv[2], p) +' "$t/image-cheetah-fictional.zip" "$t/ext4.img" + +for tool in "$XVC" "$XFP"; do + name=${tool##*/} + args=() + [[ $tool != "$XVC" ]] || args=(-p gnss) + if PATH=$t/bin:$PATH "$tool" "${args[@]}" -w "$t/work" -o "$t/out" "$t/image-cheetah-fictional.zip" > "$t/log" 2>&1; then + fail "$name: a build.prop whose copy fails is refused" + elif ! grep -qF "error: build.prop can't be read from vendor.img" "$t/log"; then + cat "$t/log"; fail "$name: a build.prop whose copy fails: says it can't be read" + else + pass "$name: a build.prop whose copy fails: refused, says it can't be read" + fi +done +((failed == 0)) || { echo "$failed check(s) failed" >&2; exit 1; } diff --git a/tools/extract-fingerprint-vendor b/tools/extract-fingerprint-vendor index e00ee35dd..8df9d285b 100755 --- a/tools/extract-fingerprint-vendor +++ b/tools/extract-fingerprint-vendor @@ -200,7 +200,7 @@ done # The vendor partition says which device it was built for. mkdir -p "$WORK/v" debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>/dev/null -[[ -s "$WORK/v/build.prop" ]] || die "vendor.img has no build.prop" +[[ -s "$WORK/v/build.prop" ]] || die "build.prop can't be read from vendor.img" dev=$(sed -n 's/^ro.product.vendor.device=//p' "$WORK/v/build.prop" | head -1) [[ "$dev" == "$DEVICE" || -n "$FORCE" ]] || die "vendor partition is for '${dev:-unknown}', not $DEVICE; use -f to override" diff --git a/tools/extract-vendor-chroot b/tools/extract-vendor-chroot index a552ec5dd..0cd68adf8 100755 --- a/tools/extract-vendor-chroot +++ b/tools/extract-vendor-chroot @@ -296,7 +296,7 @@ done # The vendor partition says which device it was built for. mkdir -p "$WORK/v" debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>/dev/null -[[ -s "$WORK/v/build.prop" ]] || die "vendor.img has no build.prop" +[[ -s "$WORK/v/build.prop" ]] || die "build.prop can't be read from vendor.img" dev=$(sed -n 's/^ro.product.vendor.device=//p' "$WORK/v/build.prop" | head -1) [[ "$dev" == "$DEVICE" || -n "$FORCE" ]] || die "vendor partition is for '${dev:-unknown}', not $DEVICE; use -f to override"