Skip to content

Fix ART iterator re-seeding root after remove - #1705

Closed
hardikkaurani wants to merge 1 commit into
pgmoneta:mainfrom
hardikkaurani:fix/art-iterator-reseed
Closed

hardikkaurani wants to merge 1 commit into
pgmoneta:mainfrom
hardikkaurani:fix/art-iterator-reseed

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary

pgmoneta_art_iterator_next() previously seeded the BFS queue from tree->root whenever iter->count == 0. Because pgmoneta_art_iterator_remove() decrements iter->count, removing the first yielded key resets iter->count to 0 and causes pgmoneta_art_iterator_next() to push tree->root onto iter->que again mid-traversal—leading to duplicate visits and a use-after-free if tree->root later collapses and is freed.

  • Track traversal initialization explicitly with bool started on struct art_iterator.
  • Add test_art_iterator_remove_collapse in test/testcases/test_art.c.

Verification

  • Formatted all modified files with clang-format.
  • Full build and test suite will run in GitHub Actions CI (Linux/macOS C build environment is not present locally on Windows).

Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:53
@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi @jesperpedersen,

I opened this small fix for pgmoneta_art_iterator_next() / pgmoneta_art_iterator_remove(), where iter->count dropping back to 0 after removing the first yielded entry caused tree->root to be re-queued mid-traversal. Added a started flag on struct art_iterator and a regression test (test_art_iterator_remove_collapse), formatted with clang-format. Please let me know if anything should be adjusted.

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 insufficient remaining quota. Try requesting a review at a lower effort level.

@jesperpedersen

Copy link
Copy Markdown
Member

Rebased and merged.

Thanks for your contribution !

@jesperpedersen

Copy link
Copy Markdown
Member

Please, cross-port to the other projects

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

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.

3 participants