Skip to content

factory-index: refuse an image zip of another build - #1120

Open
only21mil wants to merge 1 commit into
derekross:mainfrom
only21mil:build/factory-index-verify-inner-build
Open

only21mil wants to merge 1 commit into
derekross:mainfrom
only21mil:build/factory-index-verify-inner-build

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

What and why

When a factory zip's inner image-<codename>-<build>.zip names a different build from the zip's name and top folder, factory-index add records that inner image's versions under the outer build instead of refusing. android_info() now returns that path, and cmd_add() refuses a mismatch after the existing name, digest and duplicate checks, before the index is written.

Setup: Ubuntu 26.04.1 x86_64, Python 3.14.4, synthetic zip (no Google files).
Steps: Build .001 zip with .009 inner zip → factory-index add → check exit/index.

Before (a40fced5):

$ factory-index add --index factory-builds.json --codename testdev testdev-ab1c.230101.001-factory-9f61263a.zip
added AB1C.230101.001 to factory-builds.json: bootloader testloader-9.0-999, baseband testband-9.0-999, not marked tested
Check the SHA-256 against Google's page before committing: 9f61263a3b0a150edd5ebebb4f48bc5603957f25a8939b5556da064f378bf8a3
exit=0
index: AB1C.230101.001 (testloader-9.0-999, testband-9.0-999)

After (8c310516):

$ factory-index add --index factory-builds.json --codename testdev testdev-ab1c.230101.001-factory-9f61263a.zip
factory-index: testdev-ab1c.230101.001-factory-9f61263a.zip holds testdev-ab1c.230101.001/image-testdev-ab1c.230101.009.zip, not the build its name says
exit=1
index: not written

Links: base a40fced5, head 8c310516, tests/factory-index.

Not shown:

  • Real Google factory zip
  • Phone run

Device and build

  • Phone: none
  • Kernel release (uname -r): none
  • Packages changed, with versions: none

Checks (no phone needed)

  • tools/pr-check origin/main passes (7/7; checks by an AI agent)
  • tests/all passes (871 pass, 5 skip, 1 fail mark-slot-b as on a40fced; factory-index 9/9, extract-vendor-firmware 44/44)
  • tests/packages passes (or the packages I touched: none): private /tmp, 28/33 pass; same 5 fail on a40fced (dbus AppArmor, no qmake6, audio UCM); none touches this diff
  • Each changed package has its version bumped, and the new version is in the commit subject (no package changed)
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

On the phone

  • I ran this on my own phone, booted into this build
  • Runbook steps passed (plan, step, result): none
  • What I did not test: a real Google factory zip; a phone run
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)
tools/phone-smoke report
Not run: AGENTS.md §1, and this change touches only tools/factory-index and tests/factory-index (a laptop tool and its test that never run on a phone).

Generated with Gemini 4 Neon in T3 Code Nightly

factory-index add checks that the outer file name matches
<codename>-<build>-factory-<8 hex>.zip and that the top folder inside
it is <codename>-<build>, but android_info() matched any
[^/]+/image-<codename>-[a-z0-9.]+\.zip without verifying that the
inner image zip names the same build. A repacked archive whose top
folder matches the outer file name while its inner image zip belongs
to another build would record the other build's bootloader and
baseband versions under the outer build id.

Return the full inner member path from android_info() (cmd_add() is
its only caller) and update its docstring to match. In cmd_add(),
keep the top-folder check where it is and check the inner image zip
name against the lower-case build from the outer file name after the
check_build() and duplicate-build checks, before inserting and saving,
so every existing error message keeps precedence while mismatched
archives are refused before writing the index. Keep the inner-zip
selection regex unchanged so archives with zero or multiple image
zips still report the count error.

Extend tests/factory-index's factory helper with an optional inner
build id and test that patch and carrier-suffix mismatches fail with
exit 1, name the inner member, and leave the index byte-identical,
and that an inner mismatch combined with a wrong digest or an
already-indexed build still reports the existing error and leaves the
index unchanged.

Assisted-by: Gemini 4 Neon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant