Repository navigation
Conversation
parse_commit 解析 committer 时间戳原先用 strtoll,既不查 ERANGE 也不查 endptr:超长数字饱和到 ±LLONG_MAX 并透传到 stat(2) 的 st_mtime;字符集 白名单放行的 "12-34"/"1700000000-"/"-"/"--1" 分别被静默解析为 12/1700000000/0/0(issue #7)。 改用 std::from_chars 全消耗严格解析:可选 '-'、纯数字、必须完整消费、 溢出(result_out_of_range)与残留一律使整个 commit 对象解析失败。语义与 libgit2 的 git__strntol64 对齐——同一个溢出 commit 此前已使 /commits 生成 EIO,而 /branch/<name> 路径经 rawobj 却正常 stat,同仓两种语义;现在统一 为"该对象不可见"(nullopt → commit_facts_locked 失败 → EIO)。负的 pre-epoch 时间戳保持接受,与 libgit2 一致,避免误伤真实存在的早期提交。 顺带消除热路径上每次 commit 解析的 std::string 临时堆分配,并整段删除 字符集白名单判断;清理不再使用的 <cerrno> include。 单测新增:正/负溢出拒绝、19 位边界(9223372036854775807 接受且值正确、 9223372036854775808 拒绝)、残留(12-34 / 1700000000- / - / --1)拒绝、 负时间戳 -14182940 接受且值正确;既有三个 parse_commit 用例(正常±时区、 gpgsig 续行、缺头拒绝)保持绿。
|
This pull request has been automatically marked as stale because it has not had activity in 14 days. It will be closed in 7 days if no further activity occurs. |
|
Closed automatically due to inactivity. Feel free to reopen. |
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.
问题(issue #7)
parse_commit(src/rawobj.cpp)解析 committer 时间戳原先用std::strtoll(std::string(ts).c_str(), nullptr, 10),既不查errno == ERANGE也不查endptr,且字符集白名单"0123456789-"先行放行:99999999999999999999999(23 位)LLONG_MAX透传到st_mtime-99999999999999999999LLONG_MIN92233720368547758079223372036854775808LLONG_MAX12-34/1700000000--/--1-14182940(pre-epoch)一致性:同一个溢出 commit 此前在 gitmount 内部已分裂成两种语义——
/commits生成走 libgit2git__strntol64,对溢出/无数字时间戳拒绝整个对象 → EIO;而/branch/<name>路径经 rawobj 却正常 stat。本 PR 使 rawobj 与 libgit2 对齐,消除同仓两种语义。实现
src/rawobj.cpp:committer 时间戳改为std::from_chars全消耗严格解析(新增#include <charconv>)——可选-、纯数字、必须完整消费、溢出返回result_out_of_range一律使该 commit 解析为nullopt(→commit_facts_locked失败 → EIO)。负的 pre-epoch 时间戳保持接受,与 libgit2 一致。find_first_not_of("0123456789-"))与热路径上每次 commit 解析的std::string(ts)临时堆分配;清理不再使用的<cerrno>include。parse_commit→ nullopt →commit_facts_lockedrc≠0 → 分支访问 EIO、/commits 生成时该 ref 被 vlog 跳过——与 libgit2 行为一致。测试结果
tests/unit/test_rawobj.cpp新增两个用例:99999999999999999999999/-99999999999999999999、19 位边界(9223372036854775807接受且值正确 /9223372036854775808拒绝)、残留12-34/1700000000-/-/--1(旧值分别为 12 / 1700000000 / 0 / 0);-14182940 +0000接受且committer_time == -14182940。既有三个 parse_commit 用例(正常±时区、gpgsig 续行、缺头拒绝)保持绿。
改动文件已过
clang-format -i(pinned 18.1.8)。CHANGELOG[Unreleased] / Fixed已记录。风险
English summary
parse_commitparsed the committer timestamp withstrtoll, checking neithererrnonorendptr: overlong values saturated to ±LLONG_MAX and leaked intostatmtimes, and the'-'in the character whitelist let12-34/-/--1parse to garbage or 0. The same overflowing commit already failed whole/commitsgeneration through libgit2'sgit__strntol64, so gitmount exposed two semantics for one object. Fix: full-consumptionstd::from_chars(rejects overflow and residue, keeps negative pre-epoch timestamps as libgit2 does) that fails the commit object → EIO. This also drops the per-commitstd::stringtemporary and the whitelist check on the hot path. New unit tests pin the 19-digit boundary (INT64_MAX accepted, +1 rejected), residue rejection, and negative-timestamp acceptance; existing parse_commit cases stay green; build is warning-clean under-Werror; CHANGELOG[Unreleased]records the fix.Closes #7