Fix out-of-bounds write in isotopic proton removal#1
Conversation
|
[CLAUDE CODE REVIEW - claude-opus-4-6] Here's my review: PR Review: Fix out-of-bounds write in isotopic proton removalCorrectness: PASSThe fix is correct. The Checklist Review
Minor observations
Related PRsNone of the listed oss-fuzz PRs are directly related — they deal with build config, not source-level fixes. The existing LGTM[CLAUDE CODE REVIEW - claude-opus-4-6] |
The bounds check for iso_atw_diff in ichi_bns.c only validates the upper bound (<= NUM_H_ISOTOPES) but not the lower bound (> 0). When iso_atw_diff is negative (e.g. due to char truncation of large isotope mass differences at ichirvr2.c:207), the array access nNumRemovedProtonsIsotopic[iso_atw_diff - 1] writes before the array, corrupting heap metadata and causing a crash in a later free(). Add the missing lower bound check, consistent with all other similar checks in the codebase (ichirvr1.c:5552, ichirvr1.c:5653, strutil.c:3917). Found by OSS-Fuzz (coverage build crash on InChI=1/H/q+1/i1+222).
500f01e to
cd24ade
Compare
|
[CLAUDE CODE REVIEW - claude-opus-4-6] LGTM (seeded for batch CI validation of inchi) [CLAUDE CODE REVIEW - claude-opus-4-6] |
Fuzzing Coverage ReportTested: project
Per-harness
Same harness config applied to both sides (baseline = base source + PR harness). Per-harness data from |
Summary
Fix a heap-corrupting out-of-bounds array write in
ichi_bns.cthat causes crashes when processing InChI strings with large isotope mass differences (e.g.InChI=1/H/q+1/i1+222).Root Cause
The bounds check for
iso_atw_diffatichi_bns.c:5973(inside theFIX_IMPOSSIBLE_H_ISOTOPE_BUGguard) only validates the upper bound (<= NUM_H_ISOTOPES) but not the lower bound (> 0).When
iso_atw_diffis negative — which happens when a large isotope mass difference (e.g.+222) is truncated fromshorttocharatichirvr2.c:207, wrapping223to-33— the array accessnNumRemovedProtonsIsotopic[iso_atw_diff - 1]writes at index-34, far before the array start. This corrupts heap metadata, causingfree(): invalid pointerwhent_group_info->t_groupis later freed inCreate_INChI(ichimake.c:4554).Fix
Add the missing
> 0lower bound check, consistent with all other similar checks in the codebase (ichirvr1.c:5552,ichirvr1.c:5653,strutil.c:3917).Found by OSS-Fuzz. The coverage build has been failing since 2026-03-30 due to this crash during corpus merge.