aot cache file integrity - #403
Open
baibaidashixiong wants to merge 4 commits into
Open
Conversation
AOT readers copied a fixed-width footer into a non-NUL-terminated buffer and passed it to strstr(). That can read beyond the footer and make cache acceptance depend on unrelated memory. Centralize footer validation in the AOT file helper and compare the exact stored byte span before either counting or loading an AOT cache. Close a rejected counting reader so the new shared validation preserves the previous stream ownership. Signed-off-by: zqz <OrzZzznn@gmail.com>
Exercise the shared AOT footer validator with an exact footer, an equal-length byte mismatch, and a requested footer longer than the file. The coverage stays in the existing file-context test target and does not require a guest runtime or a system cache. Signed-off-by: zqz <OrzZzznn@gmail.com>
Validate cache file size before reading an AOT header and route every get_tb_num() reader exit through one mapping and stream cleanup path. Also handle open and fdopen failures in both readers, use MAP_FAILED for mmap failure checks, and avoid closing the descriptor again after fclose() in aot_load(). Signed-off-by: zqz <OrzZzznn@gmail.com>
Exercise invalid-footer and truncated-header cache paths repeatedly, then verify successful loading closes its stream without closing the descriptor twice. Also inject an fdopen() failure to verify that aot_load() closes the original descriptor exactly once. Signed-off-by: zqz <OrzZzznn@gmail.com>
baibaidashixiong
force-pushed
the
pr/aot-cache-file-integrity
branch
from
August 16, 2026 09:38
1f7018b to
429a95d
Compare
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.
Summary / 变更说明
English
Improve the correctness and resource handling of LATX AOT cache readers.
strstr()-based footer check with a shared exact-bytevalidator. The old implementation passed a fixed-width, non-NUL-terminated
buffer to
strstr(), which could read beyond the footer and make cachevalidation depend on unrelated memory.
aot_header.get_tb_num()so mapped memory and file streamsare released consistently when a cache is rejected.
open(),fdopen(),fseek(),ftell(), andmmap()failureswithout leaking resources.
mmap()failures againstMAP_FAILED.released by
fclose().invalid footers, successful reader cleanup, and
fdopen()failure handling.These changes prevent out-of-bounds reads, descriptor leaks, double-close
behavior, and unsafe handling of malformed or incomplete AOT cache files.
中文
改进 LATX AOT 缓存读取流程的校验正确性和资源管理。
strstr()尾部校验。原实现会将固定长度且未以 NUL 结尾的缓冲区传给
strstr(),可能越过缓存尾部读取,导致校验结果受到无关内存内容影响。
aot_header前检查缓存文件长度,拒绝头部不完整的缓存文件。get_tb_num()的退出和清理路径,确保缓存被拒绝时正确释放映射和文件流。
open()、fdopen()、fseek()、ftell()和mmap()的失败情况,避免资源泄漏。
MAP_FAILED判断mmap()是否失败。FILE管理并经fclose()关闭后再次执行close()。reader 清理以及
fdopen()失败等场景。这些修改可避免越界读取、文件描述符泄漏、重复关闭,以及对损坏或未完整
写入的 AOT 缓存文件进行不安全处理。
Validation / 验证
fdopen()fails.fdopen()失败时原始文件描述符仅关闭一次。Checklist / 检查项
CONTRIBUTING.md. / 我已阅读CONTRIBUTING.md。git commit -s). /每个提交都包含 DCO 签署(
git commit -s)。are not applicable. /
我已提供相关构建或测试结果,或说明了不适用的原因。