Skip to content

Fix oss-fuzz leaks from GH #209 - #292

Merged
JanCBrammer merged 5 commits into
devfrom
fix/209-oss-fuzz
Nov 3, 2026
Merged

JanCBrammer merged 5 commits into
devfrom
fix/209-oss-fuzz

Conversation

@cm-beilstein

@cm-beilstein cm-beilstein commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #209.

oss-fuzz report Result
Leak in SetInChIExtInputByExtOrigAtData Fixed: polymer unit bond list now freed after copy (inchi_dll.c)
Leak in CreateNeighList Fixed: atom list freed when there are no atoms or t-groups (ichisort.c)
Stack-use-after-return in mark_alt_bonds_and_taut_groups Already fixed on dev by d20e337; added a test that reaches the guarded line (d20e337's test did not)

The MakeIsoAtomString frame in the report is the same out-of-bounds read, not a separate bug.

Tests (test_github_209) catch these only when the library is built with -fsanitize=address; CI does not do that. The leak tests call __lsan_do_recoverable_leak_check() and are compiled in only under ASAN.

Not fixed (out of scope): some error paths of SetInChIExtInputByExtOrigAtData still leak.

@cm-beilstein
cm-beilstein requested review from djb-rwth and nnuk October 26, 2026 10:03
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Unit Test Coverage Report

Coverage Regression Summary

Metric PR (%) Base (%) Difference (pp)
Lines 33.1 27.5 +5.60
Branches 21.3 18.1 +3.20

Find details on the base coverage at https://iupac-inchi.github.io/InChI/coverage/index.html

Find details on this PR's coverage by downloading coverage-reports-41686194734 and opening html/index.html

@djb-rwth djb-rwth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cm-beilstein,
Looks fine.

@nnuk nnuk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the memory-leak fixes and regression-test additions.

No open issues 🎉

What changed in this PR

Addresses the two memory leaks reported in #209 and adds regression tests for those leaks and the previously fixed isotope-handling error.

Changes:

  • Frees temporary polymer bond lists after copying their contents.
  • Frees the unused atom-list allocation when a neighbor list is empty.
  • Adds regression tests with leak checks enabled under AddressSanitizer; detecting the isotope regression also requires an instrumented library.
File Description
INCHI-1-TEST/​tests/​test_unit/​test_github_209.cpp Adds polymer, empty-neighbor-list, and negative-isotope regression tests.
INCHI-1-SRC/​INCHI_BASE/​src/​ichisort.c Releases the unowned allocation for empty neighbor lists.
INCHI-1-SRC/​INCHI_API/​libinchi/​src/​inchi_dll.c Frees temporary polymer-unit bond lists.

Review effort: Balanced

cm-beilstein and others added 5 commits November 3, 2026 17:37
oss-fuzz #489561592 reports a 16-byte leak allocated in
SetInChIExtInputByExtOrigAtData when reading a polymer InChI. The test
feeds such an InChI to GetStructFromINCHI and asks LeakSanitizer for
leaks; it only detects them in ASAN builds.

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SetInChIExtInputByExtOrigAtData frees each temporary polymer unit and
its atom list, but not its bond list, leaking it (oss-fuzz #489561592).

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oss-fuzz #490920729 reports a 2-byte leak allocated in CreateNeighList.
With no atoms and no t-groups the atom list holds only the count slot
and is never stored in pp[0], so FreeNeighList cannot release it. The
test creates and frees such a list; only ASAN builds detect the leak.

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With zero atoms and t-groups no entry of pp points at pAtList, so
FreeNeighList, which frees pp[0], leaks it (oss-fuzz #490920729).
Free it right away in that case.

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oss-fuzz #488729177 reports an out-of-bounds read of
nNumRemovedProtonsIsotopic in mark_alt_bonds_and_taut_groups: a lone
proton with a negative isotope shift gave a negative index. d20e337
already rejects negative shifts, but its test input never reaches that
code. These inputs do; with the guard removed ASAN reports a stack
buffer overflow (i1-100) and a heap use after free (i1-1).

Fixes #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JanCBrammer
JanCBrammer merged commit 69f31d1 into dev Nov 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google oss-fuzz issues 02/2026-04/2026

5 participants