* fix(native): report non-native bytes as unrecognized, not malformed
A file that is not the format a reader owns was reported as a broken file
of that format. `inspect_native_initializers` called a PE file or random
bytes a malformed target, and the thin Mach-O reader called any bytes
without Mach-O magic a malformed Mach-O.
Format owners can now say "these bytes are not my format": parse failures
and format target failures gain the `unrecognized` kind that target
failures already define ("no reader for this operation recognizes the
bytes"). The owners report it once:
- the thin Mach-O reader, for bytes without Mach-O magic;
- the shared native container reader, for bytes that are not ELF, PE or
Mach-O (previously `unsupported`);
- the initializers provider, for a file with neither ELF nor Mach-O magic.
Function starts no longer pre-checks the header itself; the shared reader
owns that decision. IL2CPP keeps mapping unknown native bytes to its
unsupported-container reason. A recognized header that is cut off or
broken stays truncated or malformed.
* fix(resources): keep every format failure kind's facts through artifact wrappers
`ArtifactReaderFailure` kept the owner's facts only for its own list of
three format kinds, and `artifactOperationReason` had a second list. With
`unrecognized` added, `artifactFormatFailure` and `artifactParseFailure`
dropped its facts, so `translateArtifactFailure` raised an internal
invariant error instead of the target failure.
The format kinds are now one list, `FORMAT_TARGET_FAILURE_KINDS`, and
`isFormatTargetFailureKind` is the one guard. `FormatTargetFailure`,
`ParseFailureKind` and `BinaryFormatFailure` derive from that list, and
the reader-failure constructor and the operation-reason check both use the
guard, so a new kind cannot be carried by one wrapper and dropped by another.
* test(conformance): expect unrecognized for foreign bytes on native readers
The Go, Rust and native-initializers readers now report bytes that are not
ELF, PE or Mach-O as unrecognized, so their foreign-bytes conformance cases
expect that kind. The case names follow the kind.
* feat(native): list Mach-O function starts and data-in-code entries offline
The diff adds a static reader for LC_FUNCTION_STARTS and LC_DATA_IN_CODE
on one thin Mach-O or one selected slice of a universal file. Starts are
absolute VM addresses from ULEB128 deltas off the __TEXT vmaddr, and
each data-in-code entry reports offset, length, kind, and the function
start that owns its address, with one offset and limit applied to each
selected table and counts covering every entry.
inspect_macho_function_starts and inspect-macho-function-starts expose
that report, require architecture only for a universal file, and refuse
a combined table above max_entries with no partial result. The shared
load-command walk now yields each command once and stores the Mach-O
segment name and vmaddr on load regions, and the guides and limit docs
record coverage, paging, and the read and entry budgets.
* build: add advertised schema summary for inspect_macho_function_starts
* Address review feedback
* fix(native): bound function-start decoding and page before building rows
- Check each start against an interval index of executable segments, built
once, instead of scanning every segment per start.
- Walk LC_FUNCTION_STARTS once. Count and check every start and
data-in-code entry, but build result objects only for the requested page,
and resolve owners for that page during the same walk.
- Keep every declared Mach-O segment in the shared reader (macho_segments),
so a __TEXT with no file bytes still anchors the deltas, as
llvm-objdump does. LoadRegion no longer carries macho_segment.
- On 32-bit ARM, clear the Thumb tag (bit 0) from published starts and
report it as `thumb`, keeping the tagged value for the next delta, as
ld64 encodes and LLDB decodes. Wrap 32-bit images at 2^32.
- Intersect Evidence file ranges with the selected universal slice.
* refactor(native): normalize function-start format facts once
- One table, MACHO_DICE_KIND_NAMES, names data-in-code kinds for the
reader, the schema and the report check, which each had their own copy.
- Each linkedit command's dataoff/datasize is normalized once against the
slice (end, 32-bit fit, in-slice bytes) instead of the overflow check and
the in-slice length being recomputed in three helpers.
- Name CPU_TYPE_ARM, VM_PROT_EXECUTE and UINT32_MAX after their headers.
- Report coverage.text_not_at_header when __TEXT does not map file offset
0: llvm-objdump anchors the deltas on the __TEXT vmaddr and dyld on the
mach_header address, and they disagree there.
- Pin the fixture's expected starts to literal addresses.
* build: refresh the inspect_macho_function_starts schema summary after merging main
* fix(cli): keep lipo's flag name out of --architecture help text
The architecture help for four commands said "as lipo -thin does", which
the CLI option-alias check reads as a registered short flag `-thin`.
Describe the lipo behavior without spelling its flag.
* Revert "fix(cli): keep lipo's flag name out of --architecture help text"
This reverts commit 68f25adf74.
* refactor(cli): use the shared universal-slice help for inspect-macho-function-starts
* fix(native): bound decoding by max_entries and map data-in-code from the header
- Refuse a data table above max_entries from its byte count, and stop the
start walk at the remaining allowance, so the allowance bounds decoding
work. The refusal no longer claims a required_value it did not measure.
- Map each data-in-code offset as the mach_header's VM address plus the
offset, the way ld64 encodes it and dyld documents it. MH_OBJECT does not
map its header, so its base is 0. The shared container now carries
mach_header.filetype.
- Use the same header address for text_not_at_header, which also catches a
header shifted by SG_HIGHVM.
- Report a list that ends without its zero terminator as
unterminated_starts.
- Accept an observed empty section name in both result schemas.
* fix(native): tally LINKEDIT commands compactly and report a known entry total
- Count LC_FUNCTION_STARTS and LC_DATA_IN_CODE commands during the shared
load-command walk into a compact tally (two 32-bit words per command)
instead of retaining a view and an object for each one. The shared
visitor now hands over the image's byte order.
- When the image has no starts to decode, a data table above max_entries is
refused with its exact count as required_value.
* fix(native): report a non-Mach-O input as unrecognized, not malformed
Ask the shared Mach-O header recognizer before the thin reader. An ELF or
PE file passed without `architecture` has no Mach-O magic, so it is an
unrecognized target for this operation. A recognized Mach-O with a broken
or cut-off header still fails as malformed or truncated.
---------
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
* feat(native)!: give the native structural decoding allowance a per-call max_structure_bytes
The 16 MiB structural budget on native header, section, load-command and
ELF dynamic-directory table reads, and on decoded section names, was a
fixed ceiling with no override. inspect_elf_unwind_ranges,
inspect_kernel_module, inspect_elf_debug_link, inspect_dwarf_units,
inspect_binary_hardening and inspect_native_initializers now accept
max_structure_bytes (64 bytes to 512 MiB, default 16 MiB) and report
details.limit when it stops them.
binaryContainer owns the default, the limit name and the failure
(nativeStructureFailure); the directory readers take a
NativeDirectoryBudgets object in place of the positional decoded-name
budget, and Mach-O, the ELF dynamic directory and the ELF pointer
relocation pass take the same budget. Other allowances that shared the
"structure" limit name now carry their own: the PE per-name decode, the
retained DWARF section bound (derived from the admitted image), and the
hardening table-entry count. The ELF dependency provider's structural
projection was unreachable and is removed.
Part of #14235.
BREAKING CHANGE: refusals at the structural budget report
reported_limits.boundary "max_structure_bytes" instead of "structure".
* fix(native): apply max_structure_bytes to the ELF hardening dynamic table and scope its help
inspect_binary_hardening read PT_DYNAMIC under its entry count only, so a sectionless ELF could exceed the selected max_structure_bytes; the dynamic table is now checked first. The shared help no longer names tables a reader does not bound, and the limits reference states hardening's Mach-O and PE coverage. The initializer CLI recovery test asserts a parsed successful report.
* fix(native): refuse a partial ELF hardening dynamic table as malformed before its budget
* fix(macho)!: report a FAT header or table cut off by the file's end as truncated
The universal Mach-O container reader measured the file's size but
reported a FAT header shorter than 8 bytes as malformed, and a FAT table
that runs past the file's end as not FAT at all. Callers could not tell a
cut-off download from corrupt bytes.
readFatContainerHeader now returns a typed truncated state carrying the
measured file size and the length the header or table needs. A CAFEBABE
count that reads as a JVM class version stays not FAT, because a short
class file is not evidence of a universal file. Universal image
selection, the native container reader and the lipo-selected slice
resolver raise that fact as a truncated ParseFailure with an extent, and
the malformed-target projection reports it as details.available_bytes and
details.required_bytes. Complete but corrupt FAT data (zero count,
overlapping slices, slices inside the table) stays malformed.
BREAKING CHANGE: inspect_go_binary, inspect_rust_binary,
inspect_dwarf_units, inspect_native_initializers,
inspect_native_dispatch_metadata, the IL2CPP binary readers and the
macOS provider's lipo-selected slice reads now report a FAT header or
table cut off by the file's end with details.format_failure "truncated"
(previously "malformed", or an unsupported or not-universal result for a
table past the end), plus details.available_bytes and
details.required_bytes.
* test(macho): type every format-owner row with its asserted format failure
* perf(pe): stream PE import inspection over FileHandle
* perf(pe): reuse import read windows and cover positional boundaries
* fix(elf): preserve load segment range diagnostics
Route the 26 raw Buffer reads in GgufHeader and the 2 in
SafetensorsHeader through BinaryReader. Add u8, i8, i16, i32, i64,
f32 and f64 accessors to BinaryReader, with the same range checks as
u16/u32/word, since GGUF metadata stores signed and floating scalars.
Every migrated site reads an exact-size buffer from
ModelHeaderReader.take(), so outputs and errors are unchanged.
Shrink the raw-buffer-read baseline from 102 files / 711 sites to
100 / 683.
Refs #11865
* refactor(zip): read EOCD and trailing archive fields via BinaryReader
* perf(domain): avoid subarray allocations in BinaryReader and prefilter EOCD scan
Check field bounds via a private helper and read 16-, 32-, and 64-bit
integers directly from BinaryReader.bytes by offset instead of slicing
via range(), and skip non-0x50 bytes before full signature comparison
in zipEndOfCentralDirectoryCandidates.
* perf(zip): scan EOCD signature candidates with Buffer.lastIndexOf
Jump directly between 4-byte EOCD signatures with Buffer.lastIndexOf
instead of probing every byte in JavaScript, preserving reverse
candidate order, earliest-offset bounds, and zero-copy Uint8Array views.
* perf(zip): bound EOCD lastIndexOf scan to the 65557-byte tail window
Slice a zero-copy tail view starting at earliest before calling
Buffer.lastIndexOf so exhausting zipEndOfCentralDirectoryCandidates on
large archives never scans bytes before the maximum comment window.
* feat(native): carry the value of each fixed structural decoding allowance
BinaryResourceFailure and relocation-index refusals pass their maximum as limit and unit; the PE certificate decoder allowances drop the value from their names and pass it with a per-payload unit; the ELF note parser names its text ceiling with the enforced value. Kernel-module and unwind providers no longer claim a fixed text or structural allowance for a memory limit that names no ceiling (no parser produces one).
* fix(native): report a binary resource ceiling in the unit its producer counts
BinaryResourceFailure carries an optional unit; the ELF hardening entry budget says entries and the structural byte budgets say bytes. binaryResourceCeiling reports the unit only when the producer named it, so an entry count is no longer labelled as bytes. The ELF note test takes its expected ceiling from the fixture length instead of the message.
* refactor(domain): move BinaryContainer into src/domain
BinaryContainer imports only domain modules and is shared by artifacts, firmware, gpu, go, il2cpp, python, rust and native. Living under src/native made artifacts and firmware import native for its failure types and BinaryReader. Pure move: git mv plus import specifier updates.
* refactor(firmware): move the devicetree parser into src/domain/firmware
The FIT artifact reader in src/artifacts parses embedded devicetree blobs with the parser that lived under src/firmware, while firmware's providers import src/artifacts: the two units imported each other. The parser and its fixture are pure and now sit beside domain/firmware/devicetree.ts. Pure move: git mv plus import specifier and baseline key updates.
* refactor(artifacts): break the artifacts-gpu import cycle (#11335)
* refactor(artifacts): move the LZ4 block decoder into src/artifacts
Pure move: git mv plus import specifier updates. The next commit removes its GPU-specific budget.
* refactor(artifacts): take the LZ4 output budget from the caller
decodeLz4Block bounded every decode by the GPU object budget and threw through rejectGpu, so UnityFS decoding in src/artifacts imported src/gpu while gpu imports artifacts. Callers now pass their budget: GPU payloads keep GPU_OBJECT_BYTES; UnityFS passes its 64 MiB block bound, which its size checks already enforce before decoding. Malformed blocks still throw BinaryFormatFailure with the same messages.
* test(architecture): drop the artifacts-firmware and artifacts-gpu cycles from the layer baseline
* refactor(artifacts): move the PE resource reader into src/artifacts/pe (#11347)
refactor(artifacts): move the PE resource layout and parser into src/artifacts/pe
The Node SEA and Deno standalone readers in src/artifacts locate PE resources with the layout and parser that lived under src/native/pe, while those modules already read through src/artifacts (ArtifactReaderFailure, assertArtifactReadActive). Pure move: git mv plus import specifier, baseline key and spec path updates.