Fix iterator crash on single-element trees and compilation errors#25
Merged
rafaelkallis merged 5 commits intomainfrom Nov 23, 2025
Merged
Fix iterator crash on single-element trees and compilation errors#25rafaelkallis merged 5 commits intomainfrom
rafaelkallis merged 5 commits intomainfrom
Conversation
Added check for empty stack in seek_leaf() before calling get_step() to prevent assertion failure when incrementing past the last element in a tree. Co-authored-by: rafaelkallis <9661903+rafaelkallis@users.noreply.github.com>
Co-authored-by: rafaelkallis <9661903+rafaelkallis@users.noreply.github.com>
Co-authored-by: rafaelkallis <9661903+rafaelkallis@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix coredump issue when looping over single key-value
Fix iterator crash on single-element trees
Nov 23, 2025
Owner
|
@copilot make sure the tests are passing |
- Add missing #include <cstdint> to node.hpp (fixes uint16_t compilation errors) - Fix buffer underflow in step::operator++() when depth_ is 0 (sentinel node case) These pre-existing bugs prevented the repository from compiling and caused segfaults when iterating over single-element trees. Co-authored-by: rafaelkallis <9661903+rafaelkallis@users.noreply.github.com>
Contributor
Author
Tests are now passing! Fixed two pre-existing bugs that were preventing compilation and causing the crash:
All 25 tests pass: Commit: 9183cfe |
Copilot
AI
changed the title
Fix iterator crash on single-element trees
Fix iterator crash on single-element trees and compilation errors
Nov 23, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical segmentation fault that occurs when iterating past the last element in a single-element ART, along with a pre-existing compilation issue. The root cause was identified as two bugs in the iterator implementation: a buffer underflow when incrementing the sentinel step, and an empty stack access after popping the last element.
Key changes:
- Fixed compilation errors by adding missing
#include <cstdint>foruint16_t - Added bounds checking to prevent buffer underflow when incrementing iterator steps with zero depth
- Added empty stack validation in
seek_leaf()to prevent invalid memory access
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
include/art/node.hpp |
Adds missing #include <cstdint> to resolve compilation errors for uint16_t prefix_len_ |
include/art/tree_it.hpp |
Adds depth_ > 0 check before array access in step::operator++() and empty stack check in seek_leaf() to prevent crashes |
test/tree_it.cpp |
Adds comprehensive test cases for single-element iteration covering both manual iteration and for-loop patterns |
.gitignore |
Excludes CodeQL build artifacts from version control |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Iterating past the last element in a single-element ART triggers a segmentation fault due to multiple bugs in the iterator implementation.
Root Causes Fixed
1. Missing
#include <cstdint>in node.hpp (Pre-existing)uint16_t prefix_len_was undefined, causing 138 compilation errors that prevented any build#include <cstdint>to node.hpp2. Buffer underflow in
step::operator++()(Pre-existing)key_[-1], causing segmentation faultif (depth_ > 0)before accessingkey_[depth_ - 1]3. Empty stack access in
seek_leaf()(Original issue)get_step()without checking if stack was emptyget_step()asserts non-empty stack, causing crashChanges
node.hpp: Add missing#include <cstdint>to fix compilationtree_it.hpp: Add empty stack check inseek_leaf()and depth check instep::operator++()to prevent buffer underflowtree_it.cpp: Add test cases for single-element iteration edge case.gitignore: Exclude CodeQL build artifactsTest Results
All 25 tests now pass:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.