Skip to content

fix(pe): honor import directory bounds - #10044

Merged
morluto merged 2 commits into
morluto:mainfrom
ShuaixinHuang:fix/pe-import-directory-bounds
Nov 11, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
ShuaixinHuang:fix/pe-import-directory-bounds

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

触发场景

PE 的 IMAGE_DIRECTORY_ENTRY_IMPORT 和 IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 都声明了一个 RVA 与字节大小。旧解析器只用零描述符作为结束条件,忽略了目录的声明大小,因此会把目录范围之外、相邻存储的数据解释成额外 DLL。

复现:在两个 DLL 描述符的 PE32+ fixture 上,把标准导入目录大小改为单个 20 字节描述符(delay-import 对应改为单个 32 字节描述符),但保留第二个描述符和后续数据。修复前生产解析器返回 ONE.dll、TWO.dll 且 coverage.status: "complete";修复后只保留目录内的第一行,报告目录在 null 描述符前结束的 malformed entry,并将覆盖标记为 partial。

根因

标准导入和 delay-load 两个描述符循环都以映射成功和全零描述符作为边界,没有在读取槽位前验证 index * descriptor_bytes + descriptor_bytes <= data_directory.size。这让声明的来源范围和实际解析的来源范围不一致。

修复

在共享的 PE 导入解析生产边界中:

  • 标准导入按 20 字节槽位限制在其目录声明范围内;
  • delay-load 导入按 32 字节槽位限制在其目录声明范围内;
  • 未覆盖完整槽位时保留此前已解析的行,加入结构问题并返回 partial coverage;
  • 现有 RVA、映射间隙、预算、CLI/MCP、Evidence 文件位置和 imphash 行为保持不变。

同步更新 PE 导入指南,明确声明大小是解析边界。

查重与范围

直接阅读了最新 main(当前基线 c1c7a78)的 PeImportParser、PE 映射器、服务、文件系统/MCP/CLI 消费者及已有边界测试。检查了开放的 #8758(PE32 legacy delay-import 虚拟地址归一化)以及相关历史导入修复;没有发现“忽略 import data-directory size 并越界读取描述符”的相同 PR 或 issue。本 PR 不改变 legacy delay-import 能力,也不重复 #8758。

验证

  • 修复前:在基线 0e88049 的生产解析器上,标准和 delay 两个双描述符 fixture 在目录 size 缩短后都错误返回两行与 complete coverage。
  • 修复后:PE parser、service、filesystem、MCP:64 tests passed。
  • 编译 CLI 验收:9 tests passed。
  • npm run build:cached passed。
  • npm run check:fast passed。
  • npm run docs:check passed(最终 rebase 只推进 main,未改动本 PR 文件;最新提交为 dd64f98)。
  • git diff --check passed。

fixture 是静态 PE32+ 数据,未运行 Windows loader,也未声称真实样本普遍性或外部 pefile 运行时一致性。

Author readiness

Human owner: @ShuaixinHuang

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Maintainer integration validation

Integrated main 6b2f9918088c02ea00efc417051362f260d1cee2, including the CI lifecycle repair. Feature diff unchanged; current head 0d66c1c1429c62aab4227a1539ea5addecbb6a2e. Combined validation of #10138, #10085 and #10044 on this main: 222 passed, 1 host-ELF skip across 15 parser/service/filesystem/CLI/MCP suites; typecheck and lint passed. The CI repair separately passed 373 tests with 3 host-specific skips. Local macOS Node 24.22.1; fresh hosted CI pending. No Windows loader verification is claimed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T23:45:36.105003Z 0d66c1c New commits
ℹ️ 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.

@ShuaixinHuang
ShuaixinHuang force-pushed the fix/pe-import-directory-bounds branch from 7291486 to d84dbaa Compare November 11, 2026 09:10
@morluto
morluto merged commit 047d75a into morluto:main Nov 11, 2026
11 of 12 checks passed
@morluto morluto mentioned this pull request Nov 12, 2026
3 tasks done
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants