Skip to content

fix(providers): fail closed when Anthropic parse realloc fails - #80

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-3c61
Draft

fix(providers): fail closed when Anthropic parse realloc fails#80
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-3c61

Conversation

@cursor

@cursor cursor Bot commented Sep 5, 2026

Copy link
Copy Markdown

Summary

parse_response_body published text_cap / tool_cap before realloc succeeded. When grow failed, later memcpy and tool_calls[tool_count] still used the inflated cap against the live heap block.

Bug

Root cause

Capacity was doubled, then realloc could fail and leave the pointer on the old allocation. The text path still compared against the new cap and copied. The tool path continued after a failed grow, so the next tool_use skipped the grow check and wrote one slot past the array.

Fix

  • Grow helpers update cap only after a successful realloc.
  • Grow failure fails the parse, frees scratch state, and sets an OOM error instead of returning a corrupted response.

Validation

  • CI=true make test_anthropic test_provider test_router
  • GCC ASan/UBSan on test_anthropic (including forced-realloc-failure cases)
Open in Web View Automation 

parse_response_body doubled text_cap/tool_cap before realloc succeeded.
On OOM, memcpy and tool_use indexing used the inflated cap against the
live heap block. Only publish capacity after realloc and treat grow
failure as a parse error.

Co-authored-by: esadrianno <esadrianno@gmail.com>
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.

1 participant