Commit Graph
6 Commits
Author SHA1 Message Date
morluto 1a43f56354 fix(errors)!: split reader path refusals from malformed target bytes (#14225)
ArtifactReaderFailure("format") covered two different facts: target
bytes that violate their format, and a selected path that is not a
regular file. The shared selected-file projections
(projectOwnedArtifactInputFailure and classifyProviderFailure's file
step) mapped both to invalid_request with an invalid_format path
issue, so corrupt BEAM files and PE certificate table bodies were
reported as caller argument errors.

Split the reason at its producers:

- Path-kind refusals now use the existing "path" selection reason:
  regular-file admission, the stable root, directory, ZIP, ASAR and
  PyInstaller entries, dyld inputs, the UEFI flash source and extract
  occurrence selection. They stay invalid_request.
- The BEAM parser and the PE certificate table parser raise the format
  owner's ParseFailureError (malformed or truncated, format "beam" or
  "pe-certificate-table"). A short file that does not start with FOR1
  is malformed, not truncated. A PKCS#7 name encoding the decoder does
  not implement is unsupported, not malformed.
- Short reads inside an admitted range (kernel module, kernel build
  config, ELF unwind ranges) are integrity read-coverage failures,
  because the file changed during the read.
- Internal contract breaks (stream chunk size, a non-Buffer keyed
  archive chunk) are invariant violations; an impossible descriptor
  byte count is an I/O failure.

The shared projections now treat only "path" as a selection error.
They take the malformed-target facts from the reader failure's own
parseFailure, which artifactParseFailure sets once from the owner's
ParseFailureError and rebuilt failures keep through primaryFacts.
ArtifactOperationError carries the same facts, so inspect_artifact
refusals (for example Android boot images) now include
details.format_failure, format, offset and field. Android boot entry
planning raises the format owner's malformed failure, and the
redundant shortcut and API-contract format branches are removed.

BREAKING CHANGE: callers that parse `code` see unsupported_target
instead of invalid_request for malformed or truncated bytes from
inspect_erlang_beam and from the inspect_pe_certificates certificate
table body. Truncated reads of a file that changed during
inspect_kernel_module, inspect_kernel_build_config and
inspect_elf_unwind_ranges now report artifact_changed. inspect_artifact
malformed and truncated refusals gain details.format_failure and
details.format. Existing fields are unchanged.
2026-11-23 20:20:05 -05:00
morluto 89c1dd3c32 fix(errors): refuse malformed target bytes as a target, not invalid input (#14195)
* fix(errors): refuse malformed target bytes as a target, not invalid input

parseFailureAnalysisError is the shared owner that turns a byte-format
parser's ParseFailure into a public refusal. It mapped malformed and
truncated bytes to an AnalysisInputError on the path field. The envelope
then reported invalid_request, with inspect_input_contract recovery and
"correct the listed fields". The arguments were valid; the target bytes
were the problem. Readers that wrap the ParseFailureError in an
ArtifactReaderFailure, and ArtifactOperationError reason=malformed, were
classified the same way.

Add AnalysisMalformedTargetError. It keeps the parser's kind, format,
detail, offset and field, and projects as unsupported_target with
details.format_failure. Its recovery is to choose another operation or a
well-formed copy of the target. Route both parser entry points through it
and reclassify ArtifactOperationError reason=malformed. Argument and
selection errors (missing files, directories, symlinks, JSON arguments)
stay invalid_request.

Fixes #14170

* docs(maven): describe duplicate variant names as malformed metadata

Duplicate Gradle variant names go through malformedInput, which now
reports unsupported_target with details.format_failure: malformed.
Point the earlier statement at that section instead of the old
invalid_format code.

* test(errors): expect malformed-target refusals from CLI byte-format readers

Truncated IPS, ELF, PE and shortcut bytes now project as unsupported_target with format_failure=malformed. Update the CLI acceptance cases that still expected invalid_request.

* fix(errors): keep a cancelled read a cancellation whatever its abort reason

projectOwnedArtifactInputFailure read the reader failure's cause without
checking the reader's own reason. A cancelled read carries the caller's
opaque abort reason as that cause, so aborting with a ParseFailureError
turned the cancellation into a non-retryable malformed-target refusal
before the shared cancellation projection ran. Only a reader whose own
reason is malformed or truncated now yields a malformed target.

The ELF dependency checkpoint cancellation test now also aborts with a
parser failure as the reason, through the public provider read.

* test(pe): expect malformed-target refusals from the PE filesystem boundaries

Short non-PE bytes now refuse the target rather than the request field.
The missing-file, directory, symlink and child-path controls keep their
caller-input expectations.

* fix(elf): refuse malformed ELF note bytes as a target, not invalid input

inspect_elf_notes shared this PR's root cause: its parser reported
structural violations as a reader "format" failure, which the shared
stable-artifact projection treats as a request-field error, so truncated
or non-ELF bytes still returned invalid_request. The parser now raises
malformed or truncated ParseFailureErrors, which the shared projection
reports as a malformed target with format_failure and format facts.

Consumers that interpreted the old reader reason now use the parser's
facts: debug-link build-id observation keys on ParseFailureError kinds,
and binary hardening drops its rewrap of note-parser format failures
into BinaryFormatFailure, which the parser's own failure supersedes.

* test(errors): own the byte readers' malformed-target projection in one CLI table

The PR repeated the same malformed -> unsupported_target mapping in a
dedicated CLI test per command and again in each provider's filesystem
boundary test. The stable-artifact parser-failure CLI table now owns it:
every byte reader it covers (now including ELF dependencies, debug link,
unwind ranges and native initializers) refuses a truncated ELF header as
a malformed target with operation, path, format_failure, retained file
identity and no argument recovery.

Removed as redundant with that table: the truncated or non-ELF/non-PE
CLI tests for ELF debug link, dependencies, unwind ranges and notes,
native initializers, and PE imports and certificates; and the
malformed-file blocks in thirteen filesystem boundary tests, which keep
their directory, symlink, missing-file and child-path controls. Format
specific refusals (a truncated IPS body, a wrong shortcut CLSID, DWARF
units) keep their own tests, as do the owner tests in
parseFailureAnalysisError and ArtifactOperationFailure.

* test(errors): expect malformed target bytes as unsupported_target in acceptance tests

The first full acceptance run of this PR found five expectations still
asserting invalid_request for target-byte failures: the timing test's
truncated ELF, a truncated DTB, duplicate Rust dependency JSON, and PE32
and PE64 load-config images without an MZ header. Assert the
unsupported_target code, with format_failure malformed where the
non-MZ PE path matches the already-updated PE imports test.
2026-11-24 00:44:40 +00:00
morluto e59b4f6faa fix(android): validate vendor ramdisk table before capacity (#12395)
fix(android): validate vendor ramdisk table framing before capacity
2026-11-19 15:22:42 +00:00
ShuaixinHuang 90550aa223 fix(artifacts): detect AVB footers before boot page padding ends (#12046) 2026-11-18 13:03:06 -05:00
Anurag SinghandAnurag Singh bb5278c7e2 fix(artifacts): accept Android boot images without final page padding (#11857)
* fix(artifacts): accept Android boot images without final page padding

The truncation check required the file to reach the page-aligned end
after the last component, so an image holding every declared byte but
omitting the trailing zero padding was refused as truncated, and the
message named the padded end. Bound truncation by the last declared
header or component byte instead, keep the page-aligned end for
locating an AVB footer, and check the AVB original image size against
the declared bytes.

Fixes #11854

* test(artifacts): check boot image declared ends against the fixture layout

Derive each expected end from the fixture layout instead of the
parser's dataEnd, so a declared structure dropped from the coverage
check fails the test.

---------

Co-authored-by: Anurag Singh <211784907+Anurag-5ingh@users.noreply.github.com>
2026-11-17 15:06:28 -05:00
Matt Van Hornandgensokyo-dev a88c0a5554 feat(artifacts): inspect Android boot image components
Inventory Android boot and vendor_boot images through shared artifact workflows. Preserve parser failure kinds and bounded stored-component extraction.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-11-17 12:08:42 +00:00