Skip to content

fix(errors)!: refuse malformed SQLite, pwntools and EVM inputs as target failures - #14268

Merged
morluto merged 63 commits into
mainfrom
fix/adapter-target-failures
Nov 25, 2026
Merged

morluto merged 63 commits into
mainfrom
fix/adapter-target-failures

Conversation

@morluto

@morluto morluto commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Depends on #14265. The base branch is #14265's, so the diff shows only this PR.

Third PR of the #14239 stack. It covers the last three of the six adapters #14225 listed (#14265 covered trace, NTFS and release exposure).

Root cause

The SQLite engine, the pwntools ELF worker and the EVM worker each reported corrupt selected bytes with a format reason. Their adapters then mapped that reason to invalid_request with an invalid_format issue on path, which blamed the caller's argument for the file's bytes.

Structural fix

  • SQLite. The owner vocabulary SQLITE_INSPECTION_REASONS renames format to malformed. The rename covers the worker, the inspection code and the catalog-name filter. rejectedReply builds AnalysisTargetFailureError(operation, selectedPath, { kind: "malformed", format: "sqlite" }). The old rejectedArgument.format entry is deleted.
  • pwntools. PwntoolsDecoderProfile gains targetFormat (elf for inspect_binary_layout, elf-core for inspect_recorded_crash), and the decoder translates the worker's format reply into a malformed target failure at input.path.
  • EVM. inspect_evm_interface does the same, with format evm-bytecode.
  • Registry. tests/support/targetFailure/readers/adapters.ts registers SQLite (not-a-database, malformed). pwntools and EVM need external runtimes, so their cases stay in the provider boundary tests.

Design notes

  1. One translation, at the protocol boundary. The pwntools (Python) and EVM workers define their own reply schema. Their format wire reason is translated exactly once, in the adapter that owns the schema. Renaming the wire value too would touch the Python bridge and its tests (about 50 sites). That rename is left for the final guard PR, where the guard has to exempt or rename worker protocols anyway.
  2. The file is named, not the field. The refusal carries details.path, the selected file, plus format. It no longer carries an issues[] entry that pointed at the request.
  3. Caller action. The table gives retryable: false and "choose another target". There is no inspect_input_contract recovery, because the arguments were valid.

Tests

  • sqliteDatabaseProvider.test.ts now asserts that non-SQLite bytes project as unsupported_target, with failure_kind malformed, format sqlite, the path, and no recovery. The column-identity and codec tests expect the owner's malformed reason.
  • The EVM and pwntools reply-scenario tables expect AnalysisTargetFailureError for the format scenarios.

Validation

  • npx vitest run on src/sqlite, src/evm, src/native/pwntools, tests/boundary/{sqlite,evm,binaryDiagnostics} and pwntoolsArtifactCleanup: 400 passed and 125 skipped (they need evmole or pwntools on the host). The SQLite provider test failed locally, because its worker runs from the stale local dist/ and still emits format. CI builds dist/ first.
  • Scoped tsc over the 190 files that name SQLite, pwntools or EVM: clean. Also clean: oxfmt, oxlint and architecture-guards.
  • Mutation checks (on fix(errors)!: raise container reader byte faults as malformed or truncated targets #14265's code, which this branch includes): restoring truncated → truncated in the classification table fails ArtifactOperationFailure.test.ts, and making ASAR's "header leaves its observed container" malformed fails asarHeaderAdmission.test.ts. Both pass after revert.
  • Not verified locally: the real pwntools and evmole runtimes. Simulated worker replies cover the projection only.

Removed tests and the registry case that covers each

Removed Registry case
sqliteDatabaseProvider.test.ts: "rejects malformed databases without altering the selected file" adapters.ts, inspect_sqlite_database/not-a-database. Same bytes; it checks both adapters, the target facts and that the file is unchanged.

No mutation check was run locally for this removal. The SQLite worker runs from dist/, so the registry case needs the compiled CLI, and CI runs it. The pwntools and EVM reply suites stay as they are, because they need Linux x64 runtimes the registry cannot assume.

Remaining cleanup

  • The pwntools, pwndbg and EVM wire reason format, and pwndbg's format→AnalysisOutputError mapping, are renamed in the final guard PR.

…conformance registry

Introduce one domain-owned TargetFailure value whose kind alone derives
the public code, category, retryability, recovery and details, for CLI
and MCP alike. Selected-file malformed and truncated refusals are the
first area on it: AnalysisMalformedTargetError is replaced by
AnalysisTargetFailureError, and ParseFailure's byte-structure variants
are TargetFailure variants rather than a parallel type.

The shared stableArtifactParserFailureCli loop is replaced by a
declarative registry (tests/support/targetFailure/readers/*.ts) and one
generated suite that runs every registered case through the CLI and MCP.

BREAKING CHANGE: selected-file malformed and truncated refusals add
details.failure_kind, and a truncated target's remediation now says to
re-acquire the complete file instead of choosing another target. Codes
are unchanged. Affected operations: every operation that refuses a
selected file's malformed or truncated bytes, including the ELF, PE,
Mach-O, DWARF, Go, Rust, BEAM, pyc, devicetree, Apple IPS, kernel
module, binary hardening, managed PE/CLI and IL2CPP readers.
#14225 refuses a non-regular dyld input as ArtifactReaderFailure("path");
dylibFileLifetime still expected "format" and fails on main's shard 9.
stableArtifact expected "format" for an impossible descriptor byte count
(now io) and an invalid chunk size (now InternalInvariantError);
directoryArtifactReaderOpen expected "format" for a non-file entry (now
path, the same change as #14238). All three fail on main.
…cated targets

Delete the ambiguous `format` reason from ArtifactReaderFailure and
ArtifactOperationError. Each container reader now raises its owner's
fact once, through malformedArtifact / truncatedArtifact, with format,
offset, field and measured extents. Short reads inside a measured extent
are read-coverage integrity failures, path-kind refusals are `path`,
foreign or recovery-requiring inputs are `unsupported`, host tool output
is `io`, and REA defects are InternalInvariantError.

The trace, NTFS journal, release exposure, web capture, native macOS and
web artifact adapters project the reader's parsed facts as
AnalysisTargetFailureError instead of invalid_request. Inventory
malformed, truncated, unsupported and cancelled reasons take their code
from the TargetFailure projection table, so a truncated container is
unsupported_target with failure_kind "truncated" on both paths.

BREAKING CHANGE: inventory_artifact, inspect_artifact, extract_artifact,
analyze_javascript_application, inspect_desktop_application,
inspect_keyed_archive, inspect_asset_catalog, inspect_nuget_nupkg,
trace_dylib_resolution, trace_web_module_imports and
trace_web_source_location report damaged container bytes as
unsupported_target (details.reason "malformed" or "truncated", with
failure_kind and format) instead of artifact_operation_failed with
reason "format", and a truncated container as unsupported_target instead
of truncated. inspect_playwright_trace, inspect_ntfs_journal,
audit_release_exposure, the web capture inspection operations and the
caller-selected import and source maps report damaged selected bytes as
unsupported_target instead of invalid_request. The `format` reason no
longer appears in details.reason.
…get failures

The SQLite engine's `format` reason is renamed to `malformed` at its
owner (SQLITE_INSPECTION_REASONS), and its refusal becomes an
AnalysisTargetFailureError at the selected path with format "sqlite".
The pwntools and EVM worker replies keep their wire reason "format",
which their workers define, and the adapters translate it once into a
malformed target failure with the profile's format (elf, elf-core,
evm-bytecode) instead of an invalid_format argument issue. SQLite joins
the target-failure conformance registry.

BREAKING CHANGE: inspect_sqlite_database, inspect_binary_layout,
inspect_recorded_crash and inspect_evm_interface report a selected
file's malformed bytes as unsupported_target with details.failure_kind
"malformed", format_failure, format and path, instead of invalid_request
with an invalid_format issue on path.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T03:00:29.891860Z
We couldn’t complete this review. Comment @codex review to try again.
83ed786 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

… reference page

artifact_integrity_mismatch's projection schema requires declared and
calculated digests, which a TargetFailure of kind integrity does not
carry, so the kind now projects artifact_operation_failed with category
integrity_mismatch. The model test validates every kind's projection
against analysisErrorProjectionSchema. The reference page joins the
documentation sidebar.
…odel

# Conflicts:
#	tests/boundary/filesystem/stableArtifact.test.ts
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new blocking issue found.

Summary

SQLite, pwntools and EVM now report malformed selected files as target failures rather than bad request arguments. Pwntools also preserves a distinct truncated reason for short headers.

  • SQLite refusals now identify the selected file as the problem.
  • ELF and core-file checks now report damaged bytes as target failures.
  • EVM bytecode refusals now point to the selected code file.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Selected file] --> B[Worker or SQLite engine]
  B --> C{Refusal reason}
  C -->|Malformed bytes| D[AnalysisTargetFailureError: malformed]
  C -->|Short ELF header| E[AnalysisTargetFailureError: truncated]
  D --> F[Shared CLI and MCP error projection]
  E --> F
  F --> G[unsupported_target with selected path and format]
Loading

Reviews (16) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

…p unsupported desktop probes local

A Bun or Node SEA short read inside a range already checked against the
measured size meant the file changed, not that it was truncated. The
carrier range reader and Bun's readExact now raise read-coverage
integrity for it, and keep 'outside the file' as the truncated case.
DesktopFileInspection records an unsupported managed-metadata probe as a
row issue again, so later file checks still run.
…ly suites

The literal-replacement scenario now reads the failure's detail instead
of an issues[] message, and a malformed reply wrapped by cleanup failure
reports category unsupported_target.
…d drop their per-command copies

The non-MZ PE imports and load-config cases (PE32/PE32+, ZZ and high-bit
signatures) and the truncated Apple IPS body move into the conformance
registry, which runs them through the CLI and MCP and now also checks
that a refusal leaves the selected file unchanged. The per-command tests
keep only their valid-image controls.
…ce registry covers

inspect_sqlite_database/not-a-database in the target-failure registry runs
the same non-SQLite bytes through the CLI and MCP, asserts the malformed
target facts and checks the selected file is unchanged.
Comment thread src/native/pwntools/PwntoolsDecoder.ts Resolved
…etry from it

Apply the owner review on #14239 to the TargetFailure model:
- remove details.format_failure; failure_kind is the only identifier;
- give integrity, conflict and io their own codes
  (target_integrity_mismatch, input_conflict, host_io_failed) and derive
  inventory malformed, truncated and unsupported codes from the same table;
- add a retry hint (none, backoff, after_change) derived from the kind,
  with io refined by its transient errno fact; retryable stays the
  unchanged-retry flag and is true exactly for backoff;
- rename the limit-cut result code and category truncated to partial;
- drop cancelled and resource from the target kinds and spell
  identifiers in American English (unrecognized);
- return a target failure a tool handler throws as a projected isError
  result instead of letting the SDK flatten it to text.

BREAKING CHANGE: details.format_failure is removed (read
details.failure_kind). The truncated result code and category are now
partial. Target integrity failures report target_integrity_mismatch,
host read failures host_io_failed and disagreeing inputs input_conflict.
Inventory operations (inventory_artifact, inspect_artifact,
extract_artifact and the other inventory callers) report truncated
container bytes as unsupported_target. Every target failure carries a
top-level retry hint.
…fix/container-reader-target-failures

# Conflicts:
#	src/resources/AsarHeader.ts
…puts in real-provider verifiers

The binary-layout, recorded-crash and EVM verifiers still expected invalid_input for malformed or truncated selected bytes. The pwntools and EVM adapters now report those as unsupported_target with failure_kind; a missing path remains invalid_input.
The limit-cut code is partial; this Windows-lane test arrived from main with the old truncated spelling.
morluto and others added 15 commits November 24, 2026 17:55
…odel

# Conflicts:
#	docs/.vitepress/documentation.ts
#	docs/README.md
#	tests/boundary/go/goBinaryProvider.test.ts
#	tests/boundary/mcp/nodeSeaMcp.test.ts
#	tests/fixtures/go/image.ts
…fix/container-reader-target-failures

# Conflicts:
#	src/artifacts/NodeSeaArtifactReader.test.ts
#	src/artifacts/UImageArtifactReader.boundaries.test.ts
#	src/artifacts/UImageArtifactReader.ts
#	src/artifacts/UnityFsArtifactReader.boundaries.test.ts
#	src/artifacts/WxapkgArtifactReader.boundaries.test.ts
#	src/artifacts/inventory/classify.ts
#	src/resources/ZipArtifactReader.ts
#	tests/acceptance/nodeSeaCli.test.ts
#	tests/boundary/filesystem/artifactZipIntegrity.test.ts
#	tests/boundary/mcp/nodeSeaMcp.test.ts
The stdio transport removes the private structured carrier from every isError result, so the conformance suite asserted a field that never reaches clients and failed every case. The projected diagnostic is checked from the JSON text instead.
…fter inventory

Bundle resources replaced after open and unselected JavaScript sources rewritten after inventory now fail a change check, so they report artifact_changed with retry backoff rather than artifact_operation_failed.
The digest the session admitted does not change when the same request is
repeated, so targetDigestChangedFailure was inviting a backoff retry that
fails the same way. It now names admitted-identity, which stays
artifact_operation_failed and not retryable, and tells the caller to reopen.

Co-authored-by: morluto <[email protected]>
zlib stops at the first complete stream, so a declared span that arrives
intact but is not fully consumed is trailing junk or a second stream, not
a file that changed. A source that ends before that span stays read-coverage.
The cached-carrier test replaces the file with a different size so a shared
timestamp cannot hide the rewrite.

Co-authored-by: morluto <[email protected]>
A trace member whose CRC fails is a malformed zip target. The partial
Evidence assertion now checks that code, failure_kind and format.

Co-authored-by: morluto <[email protected]>
The session keeps the digest it admitted, so replacing the executable and
repeating trace_dylib_resolution is not a retryable container change.

Co-authored-by: morluto <[email protected]>
Base automatically changed from fix/container-reader-target-failures to main November 25, 2026 02:17
@morluto
morluto merged commit a61ff39 into main Nov 25, 2026
57 checks passed
@morluto
morluto deleted the fix/adapter-target-failures branch November 25, 2026 02:54
morluto added a commit that referenced this pull request Nov 25, 2026
Brings in the failure-model stack (#14247, #14265, #14268, #14272,
#14277, #14281, #14289). Target failures reach MCP through
toErrorToolResult and the CLI through projectCliAnalysisResult; neither
path calls the budget decision, so their projection is unchanged.

Conflicts: the Android verifiers keep main's sha256File helper and this
branch's complete-evidence wrappers; the ELF and Rust MCP tests and the
EVM description take main's version, since the harness default already
requests complete Evidence. A leftover delivery reassignment in the
EvidenceMcpServerCore constructor, already set by its parameter
property, is removed.
@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working labels Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants