fix(FUN-5): replace NSAssert in getNextCharacter with unconditional bounds guard#236
fix(FUN-5): replace NSAssert in getNextCharacter with unconditional bounds guard#236kostub wants to merge 1 commit into
Conversation
…ounds guard NSAssert is compiled out in release builds (NS_BLOCK_ASSERTIONS), leaving an unchecked heap read if any call site ever reaches getNextCharacter past the end of input. Replace with an unconditional if-guard that sets MTParseErrorInternalError and returns 0 — consistent with the parser's existing setError convention. All current call sites pre-check hasCharacters, so this is defense-in-depth with no behavior change on any reachable path. Adds a regression test confirming valid \frac parsing is unaffected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request replaces an NSAssert with an unconditional bounds check in getNextCharacter to prevent potential out-of-bounds heap reads in release builds. It also adds a regression test to ensure that this defense-in-depth guard does not affect valid parsing. There are no review comments, so no feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
EM-REVIEW v1 Verdict: Approve-worthy (non-blocking). No issues found. Reviewed the diff ( Correctness of the guard — confirmed
No valid-input behavior changed — confirmedThe replacement is semantically identical to the old Test — reasonable
Minor (non-blocking) notes
Defense-in-depth fix, clean and well-documented. Recommend merge. |
Summary
getNextCharacterprotected its array read only withNSAssert, which is compiled out in release builds (NS_BLOCK_ASSERTIONS), leaving an unchecked heap read if any call site ever calls past the end of input.NSAssertwith an unconditionalif (![self hasCharacters])guard that setsMTParseErrorInternalErrorand returns0— consistent with the parser's existingsetError:convention.hasCharactersbefore callinggetNextCharacter, so this is defense-in-depth with no behavior change on any currently-reachable path.testGetNextCharacterBoundsGuardDoesNotAffectValidParsing) confirming that valid\fracparsing is unaffected.Files changed
iosMath/lib/MTMathListBuilder.m— replaceNSAssertwith unconditional guard (~+8/-1 LOC)iosMathTests/MTMathListBuilderTest.m— add regression testTest plan
swift buildpasses (no warnings)swift test— all 293 tests pass, including new regression testif, notNSAssert)🤖 Generated with Claude Code