SGFragment::getAtomCoordinates warns on a bad index and then reads out of range

未关闭
#1,315 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c
领域
desktop

调研方向

Read src/viz/sgcommands/SGFragment.C around line 249 and inspect callers of Fragment::atomIndex, whose implementation is at src/tdat/chemistry/Fragment.C:3859. First check how callers handle the not-found INT_MAX result and whether getAtomCoordinates can safely return early. Done means invalid indices cannot reach the vector access, the boundary check rejects index == size(), and relevant callers are audited.

由索引模型根据 Issue 内容生成。

描述

SGFragment::getAtomCoordinates (src/viz/sgcommands/SGFragment.C:249) guards the index like this:

EE_RT_ASSERT(index<=p_atoms.size(), EE_WARNING, "index exceeds atoms");
const double *coords = p_atoms[index]->coordinates();

Two faults in two lines:

  1. The severity is EE_WARNING, so a bad index logs a line and then falls straight into p_atoms[index]. The check does not protect anything.
  2. The comparison is <=, off by one: index == size() passes the guard and is still out of range.

The usual source of a bad index is Fragment::atomIndex, which returns INT_MAX when the atom is not found (src/tdat/chemistry/Fragment.C:3859). That return value is not exceptional: TAtm::operator== is identity-based (return (this == &atom);, src/tdat/chemistry/TAtm.C:237), so any atom belonging to a different Fragment yields INT_MAX, even when the two fragments hold the same molecule. p_atoms[INT_MAX] is then a read about 17 GB past the vector's data pointer — in practice a SIGSEGV, undefined behaviour in principle.

Found while diagnosing #1306, where a process-wide dragger event makes one Builder tab run its move callback against another tab's atoms and reach exactly this path. The scoping fix for #1306 closes that one caller; this guard is the shared hazard behind it, and every caller that passes an atomIndex result is exposed.

Suggested fix: make the guard an early return (or an EE_FATAL if callers cannot sensibly continue) and correct <= to <. Then audit the callers of Fragment::atomIndex for unchecked INT_MAX.

主要语言
C
星标
10
派生
8
平均合并
6 小时 32 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

FriendsofECCE/ECCE 的其他 Issue

查看 FriendsofECCE/ECCE 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。