Repository navigation
fix(pe): honor import directory bounds - #10044
Merged
morluto merged 2 commits intoNov 11, 2026
Merged
Conversation
Codex Review Summary: ✅ CompletedThis 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. |
ShuaixinHuang
force-pushed
the
fix/pe-import-directory-bounds
branch
from
November 11, 2026 09:10
7291486 to
d84dbaa
Compare
ShuaixinHuang
force-pushed
the
fix/pe-import-directory-bounds
branch
from
November 11, 2026 10:58
d84dbaa to
dd64f98
Compare
This was referenced Nov 11, 2026
3 tasks done
8 tasks
This was referenced Nov 13, 2026
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.
触发场景
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 导入解析生产边界中:
同步更新 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。npm run build:cachedpassed。npm run check:fastpassed。npm run docs:checkpassed(最终 rebase 只推进 main,未改动本 PR 文件;最新提交为dd64f98)。git diff --checkpassed。fixture 是静态 PE32+ 数据,未运行 Windows loader,也未声称真实样本普遍性或外部 pefile 运行时一致性。
Author readiness
Human owner: @ShuaixinHuang
Maintainer integration validation
Integrated main
6b2f9918088c02ea00efc417051362f260d1cee2, including the CI lifecycle repair. Feature diff unchanged; current head0d66c1c1429c62aab4227a1539ea5addecbb6a2e. 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.