feat: 添加 trace 结构清理脚本与产物 - #27
Open
xy200303 wants to merge 1 commit into
Open
Conversation
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.
概述
本 PR 针对 #5 新增一套保守的
trace结构异常检测与修复流程,用于清理data/entries.jsonl中部分尚未人工校验样本的调用链结构问题。主要变更:
scripts/trace_structure_cleanup.py,支持check和fix两种模式。{file, line, code}完全相同的重复 trace 节点。entry_point或晚于critical_operation的 trace 节点。"start-end"区间行号。data/entries.trace_fixed.jsonlreports/trace_structure_fix_log.csvreports/trace_structure_fix_log.jsonlreports/trace_structure_report.mdscripts/README_trace_structure_cleanup.md,说明运行方式、处理策略和限制。tests/test_trace_structure_cleanup.py,覆盖重复节点、desc冲突、区间行号、跨文件跳过、保守修复和 bounds 修复策略。为什么这样做
trace字段用于描述从entry_point到critical_operation的证据链,是 VulnGym 作为白盒漏洞检测 benchmark 的关键 ground truth。当前部分verify = 0数据中存在结构性噪声,例如:"start-end"区间;如果这些问题直接进入评测,会影响调用链解释质量,也会增加后续人工审核成本。因此本 PR 的目标不是激进重写 trace,而是提供一套可复现、可审计、默认保守的清理工具:完整扫描和记录问题,只自动修复确定性较强的场景,把模糊情况留给人工复核。
设计取舍
1. 默认保守,不重排 trace
脚本不会对 trace 做排序。原因是 trace 表达的是跨函数、跨文件、跨模块的调用或数据传播链,而不是单文件内的源码顺序。简单按行号重排可能让跨文件调用链变得错误。
因此,本 PR 只在 trace 节点和
entry_point/critical_operation位于同一文件时进行行号边界比较;跨文件节点保持原始顺序。2. 默认只修复
verify = 0verify = 1数据已经通过人工审计,自动修改风险更高。默认fix模式只作用于verify = 0样本。如果维护者希望扩大修复范围,可以显式执行:
3.
critical_operation之后的节点默认只记录同一文件内晚于
critical_operation的 trace 节点虽然可疑,但不一定总是错误。有些标注可能把 critical operation 定位到核心表达式,同时在 trace 中保留外层块、调用上下文或收尾语义。为避免误删有价值的上下文,默认策略只将这类节点记录为人工复核项。
如果维护者希望采用更严格的边界修复策略,可以执行:
4. 重复节点默认采用 safe 策略
当两个 trace 节点的
{file, line, code}完全一致时,脚本会将其视为重复候选。但如果两个节点的desc不一致,说明标注者可能试图表达不同语义阶段。因此默认
safe策略会保留这类节点并写入人工复核日志,避免丢失解释信息。如果维护者确认只需要按结构去重,可以执行:
修复结果
使用默认保守修复策略运行:
扫描结果:
默认自动修复了 2 个确定性越界 trace 节点:
entry-00103entry-00320issue 中点名的样本处理结果如下:
entry-00103entry-00320entry-00185entry-00511这种处理方式可以先消除低风险结构噪声,同时避免对仍可能具有语义价值的 trace 节点做不可逆删除。
重复 PR 检查
已检查当前开放 PR,发现已有多个 PR 也在处理 issue #5,包括 #9、#10、#17、#18、#22 等。
本 PR 仍基于
main独立提交,主要差异是:verify = 0。check/fix、重复节点处理策略、顺序边界修复策略设计为可配置参数。验证
已运行:
验证结果:
examples/load_dataset.py可正常加载 184 reports / 408 entries。data/entries.trace_fixed.jsonl再次执行 check,不会产生新的结构修改。git diff --cached --check无 whitespace 错误。Closes #5