Repository navigation
fix: heap overflow when copying an undirected graph into a CSR - #670
Merged
Becheler merged 3 commits intoOct 28, 2026
Merged
Conversation
|
Boost dependency footprint vs Header-inclusion weights (graph files pulling each direct dependency in):
Transitive Boost modules: 47 → 47 (0) |
Becheler
force-pushed
the
fix/csr-copy-from-undirected
branch
from
October 26, 2026 12:23
fc8e4e6 to
f6084ed
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
|
Compiler-warning counts vs
|
Becheler
force-pushed
the
fix/csr-copy-from-undirected
branch
from
October 26, 2026 14:25
7d5fbe0 to
62ed6e2
Compare
Becheler
marked this pull request as ready for review
October 27, 2026 11:38
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.
fixes a memory bug that happens when copying an undirected graph into a CSR graph.
Motivation
The CSR copy code tries to detect an undirected source so it can reserve room for twice as many edges, since an undirected edge shows up from both ends. The check compares against undirectedS, but an undirected graph reports undirected_tag, so the check never matches. The CSR therefore gets room for E edges and then writes 2E into it. That is a heap overflow that can crash or silently corrupt memory, and it has been there since the 2009 fix for ticket #3357.
What this PR does
Instead of guessing from the graph's type, the CSR counts the edges it will actually copy by adding up out_degree over all vertices. That is always the exact size, self-loops included.
note:
num_edgeson a filtered_graph returns the unfiltered edge count, so summing out_degree over every vertex is the only way to size the CSR to exactly the edges the copy will write, at a cost of one extra pass that is no larger than the copy itself. Copying a 1M-vertex, 16M-edge graph into a CSR took 57.3 ms with the fix versus 56.7 ms on develop, which is inside noise rnage (something like ~1%), while an alternative that skips the counting pass to grow the array while copying took ~3x longer (179 ms).Before submitting
developbranch.Kind of change
Tick exactly one. Each kind is reviewed differently, so mixing them in one PR makes the diff difficult to review (why).
Change category