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

Aberta
#1,315 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
55/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
c
Domínio
desktop

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
C
Estrelas
10
Forks
8
Merge médio
6h 32min
PRs com merge (30d)
1

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de FriendsofECCE/ECCE

Todas as issues de FriendsofECCE/ECCE

Issues semelhantes

Mais issues de C

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.