Repository navigation
fix(pe)!: bound static readers by the bytes they read, not file size - #14262
Merged
Merged
Conversation
…eaders Resources and certificates now admit headers through readPeImage, and resources map RVAs through the shared file-backed mapping. The owner reads the optional header at fixed offsets, caps data directories at 16, and lets a PE signature at e_lfanew override a DOS relocation table. Export, import, TLS and resource directories are read at their RVA whatever Size declares. Disregarded declarations are reported in header_anomalies. BREAKING CHANGE: import and delay-import walks continue to the null descriptor past a short directory Size instead of stopping with a malformed_entry issue, and inspect-pe-resources reports an unsupported optional-header magic as unsupported_target.
Only a relocation table that describes no DOS load module yields e_lfanew to a PE signature; update MZ/PE conformance to the shared owner.
max_file_bytes now counts the header prefix and every positional read of headers, directory tables and their referenced ranges. The identity pass that hashes the whole file is bounded only by a fixed whole-file ceiling: 4 GiB minus one byte for the PE-only readers, whose file offsets are 32-bit, and 512 MiB for hardening and exports. An exhausted allowance is a capacity refusal with a typed parameter details.limit. BREAKING CHANGE: max_file_bytes no longer refuses a large file whose reads fit; an exhausted read allowance reports resource capacity instead of file-size, and only a file above the fixed ceiling reports file-size.
The resource walk is bounded by the file-backed run from the directory RVA rather than its Size, and a Size that ends before the bytes walked is a directory_size_below_structure anomaly. The TLS result carries structure_location for the structure read past a short Size, and Evidence cites it.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
[Medium impact] The PR appears safe to merge; no new blocking issue was found. SummaryThe six static readers now count header-prefix and positional reads against
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Selected file] --> B{Within fixed whole-file ceiling?}
B -- No --> C[file-size refusal]
B -- Yes --> D[Stream SHA-256 and retain header prefix]
D --> E[Charge prefix and positional reads]
E --> F{Within max_file_bytes?}
F -- No --> G[capacity refusal with parameter details]
F -- Yes --> H[Parse tables]
H --> I[Check file stability and close]
I --> J[Return report]
Reviews (8) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
…MZ headers malformed An oversized resource Size is reported without requiring its unused bytes to map. A Windows-header candidate is malformed when the DOS module is also invalid, and the guide states that a valid DOS relocation table owns e_lfanew.
…4263) * feat(pe): report image_base and IAT slot VAs in static PE results Every static PE result reports the optional-header image_base once as a hex VA, and import rows add iat_va beside iat_rva so a slot goes straight to xrefs. Fields name their space as rva, va or file_offset; the new fields are optional so saved Evidence still parses, and the imports service rejects an iat_va that disagrees with image_base plus iat_rva. * fix(pe): document iat_va for rebased databases and test VA rejection iat_va is relative to the file's ImageBase; a rebased provider database needs its own base plus iat_rva. Cover the service rejection of a slot VA that disagrees with image_base plus iat_rva.
…ission # Conflicts: # docs/guides/native/binary-diagnostics.md # src/domain/native/nativeExportParser.ts # src/domain/native/nativeExports.ts # src/domain/native/peCertificates.ts # src/domain/native/peImports.ts # src/domain/native/peLoadConfig.ts # src/domain/native/peResources.ts # src/domain/pe/peResourceLayout.ts # src/native/pe/PeCertificateParser.ts # src/native/pe/PeImportParser.ts
…ission # Conflicts: # docs/reference/limits-and-recovery.md
22 of 29 tasks
morluto
enabled auto-merge (squash)
November 24, 2026 14:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#14253 has merged and this PR now targets
main. #14263 (theimage_baseandiat_vaaddress vocabulary, reviewed there) was squash-merged into this branch, so this PR also carries that change. Its description, validation and threads are on #14263.Root cause
inspect-pe-imports,-resources,-load-config,-certificates,inspect-binary-hardeningandinspect-native-exportspassedmax_file_bytestowithStableArtifactHandleas a whole-file size gate. These readers already read by position, through a 4096-byte header prefix andreadRange. The only stage that touches every byte is the identity pass, which streams the file once in fixed chunks to compute its SHA-256 and retains only the prefix. The gate therefore tracked no resource the readers use. A 181 MB PE was refused by default, even though its tables are a few hundred KiB.Fix
withStableArtifactHandlegains an optionalreadBudget(ArtifactReadBudget, fromsrc/domain/artifactReadBudget.ts).budgetArtifactReads(src/resources/artifactReadBudget.ts) counts the parsed header prefix and every positional read against it, and refuses before the read that would exceed it. The six readers passmax_file_bytesas that allowance. The parameter keeps its name, default (64 MiB, or 256 MiB for exports), floor and maximum. Its description now says it bounds the bytes read, not the file size.artifact.bytesis a u32. It is 512 MiB, the existing schema ceiling, for hardening and exports, which also read ELF and Mach-O. A file above it gets afile-sizerefusal naming that fixed allowance (artifactFileCeilingConstraint).capacityrefusal (artifactReadBudgetConstraint). It carries a typeddetails.limit(control_kind: "parameter",parameter: "max_file_bytes", effective value, bounds, default andapplies_at: "next_call"), andreported_limits.required_read_bytesholds the reads needed so far. The remediation says to raise the parameter, or names the ceiling when that is not possible.artifact.bytesexceedsmax_file_bytes.ArtifactReaderFailure("limit")/AnalysisResourceConstraintError, and [Design] One owned target-failure model with derived CLI/MCP projections and a declarative reader conformance registry #14239 migrates them toTargetFailure'sresourcekind. The resource-constraint constructor baseline nets 3 removed and 2 shared added, insrc/resources/artifactReadBudget.ts.docs/reference/limits-and-recovery.md, linked from the tool pages.rea-numeric-limitsstays green. The limit inventory has no entries for these per-call parameters.Breaking behaviour:
max_file_bytesno longer refuses a large file whose reads fit. An exhausted allowance now reportscapacityinstead offile-size. Only a file above the fixed ceiling reportsfile-size.Large public PE
The test file is
Godot_v4.7.2-stable_win64.exe(180,858,888 bytes, SHA-256ab1824f8…2424, from the official release zip). It was not executed. Each run was in-process, from source throughtsx, with default inputs. Peak RSS is from/usr/bin/time -land includes the tsx loader.Read counts come from a temporary counter that was removed before commit. Each count excludes the 4096-byte prefix, which also counts toward the allowance. These are single cold runs, not benchmarks.
corkami/pocs
PE/bin(230 MZ files) gives the same per-reader counts as #14253, because every file fits the default allowance. imports 206/24, exports 202/28, load config 204/26, resources 203/27, certificates 204/26, hardening 207/23 (ok/refused).Validation
src/resources/artifactReadBudget.test.tscovers prefix and positional accounting, the refusal before the over-budget read, the typeddetails.limit, and that other reader limits are left alone.PeResourcesProvider.test.tscovers a sparse file 4 KiB over 64 MiB with small directories, which is accepted at the default allowance. It also covers the typed refusal atmax_file_bytes: 64.readBudgetinto the handle fails the provider test.npx vitest runpassed on src/native, src/resources, src/application/binaryDiagnostics, src/domain/pe and the PE filesystem and MCP boundary suites. Also clean: scopedtsc, the push hook's full typecheck,oxlint,oxfmt, the architecture guards andrea-numeric-limits.tests/boundary/filesystem/stableArtifact.test.tshas 7 failures that predate this branch (descriptor byte counts andchunkBytes); they reproduce with this change reverted.inspect-dwarf-units(listed in [Bug] Static PE readers refuse PEs over 64 MiB by default although they read only directories #14167) is not a PE reader and still gates on file size. It can adoptreadBudgetin a follow-up.Fixes #14167