Skip to content

Fix uninitialized cell_index on API-created table cells - #392

Open
BetterAndBetterII wants to merge 1 commit into
github:masterfrom
BetterAndBetterII:fix/table-cell-index-init
Open

Fix uninitialized cell_index on API-created table cells#392
BetterAndBetterII wants to merge 1 commit into
github:masterfrom
BetterAndBetterII:fix/table-cell-index-init

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Summary

cmark_node_new_with_ext() for a table cell left cell_index uninitialized because opaque_alloc wrote a heap node_cell pointer into the same union. cmark_render_html / cmark_render_xml then indexed alignments[] with that garbage and could crash.

Initialize cell_index to 0 for API-created cells (parse path still sets the real index via set_cell_index).

Fixes #360.

Test plan

  • New api_test case: create cell with cmark_node_new_with_ext, assert cell_index == 0, render HTML/XML after replacing a header cell
  • ./build/api_test/api_test (550 passed)
  • extensions / roundtrip / CommonMark spec suites green under Asan build

opaque_alloc previously calloc'd a node_cell into the same union as
cell_index, so cmark_node_new_with_ext(TABLE_CELL) left a heap pointer
where render_html/xml expected a column index and could SEGV.

Initialize cell_index to 0 instead. Fixes commonmark#360.
Copilot AI balanced review requested due to automatic review settings August 30, 2026 09:21

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

cell_index is not initialized when a table cell is created using cmark_node_new_with_ext()

2 participants