Skip to content

Reject unweighted graphs in cugraph_sssp and cugraph_biased_random_walks - #5720

Open
morristai wants to merge 3 commits into
rapidsai:mainfrom
algeon-dev:fix-sssp-unweighted-null-deref
Open

morristai wants to merge 3 commits into
rapidsai:mainfrom
algeon-dev:fix-sssp-unweighted-null-deref

Conversation

@morristai

Copy link
Copy Markdown
Contributor

Closes #5716

A graph created without a weight array has edge_weights_ == nullptr, and the SSSP and biased random walk functors dereferenced it. Both now return CUGRAPH_INVALID_INPUT through mark_error before transpose_storage, following the input checks in bfs.cpp and neighbor_sample.cpp. The Doxygen comments for cugraph_sssp and cugraph_biased_random_walks now say that the graph must have edge weights.

Rejecting the input matches the Python cugraph.sssp wrapper and the C++ cugraph::sssp signature, which takes a required weight view. If you would rather have the C API treat missing weights as 1.0, I can change it.

New tests test_sssp_unweighted and test_biased_random_walks_unweighted build graphs with a NULL weight array and check the return code, the null result and the error message.

🤖 Generated with Claude Code

Calling cugraph_sssp or cugraph_biased_random_walks on a graph created
through the C API without a weight array segfaults. pylibcugraph.sssp
and pylibcugraph.biased_random_walks reach the same crash because they
call these functions directly.

When no weights are passed, the graph creation code in
cpp/src/c_api/graph_sg.cpp (lines 590-600) leaves edge_weights_ as
nullptr. The
sssp_functor in cpp/src/c_api/sssp.cpp reads that pointer at lines
72-73 and dereferences it unconditionally at line 105
(edge_weights->view()). The biased_random_walks_functor in
cpp/src/c_api/random_walks.cpp does the same at line 215. The uniform
and node2vec functors in the same file already handle a null pointer
by passing std::nullopt.

The Python cugraph.sssp wrapper
(python/cugraph/cugraph/traversal/sssp.py lines 188-193) already
rejects unweighted graphs with a RuntimeError that points the caller to
BFS, and the C++ cugraph::sssp and cugraph::biased_random_walks
APIs take a required weight view. The C API had no matching check.

Both functors now return CUGRAPH_INVALID_INPUT with an error message
through mark_error when the graph has no edge weights, matching the
existing input checks in bfs.cpp and neighbor_sample.cpp. The Doxygen
comments for cugraph_sssp and cugraph_biased_random_walks state the
requirement.

New C API tests test_sssp_unweighted (sssp_test.c) and
test_biased_random_walks_unweighted (sg_random_walks_test.c) build a
graph with a NULL weight array and check that the call returns
CUGRAPH_INVALID_INPUT, leaves the result NULL and sets a non-empty
error message. Both tests segfault without this change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@morristai
morristai requested a review from a team as a code owner October 21, 2026 03:33
@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ChuckHastings

Copy link
Copy Markdown
Collaborator

/ok to test 38d38c2

@ChuckHastings ChuckHastings added bug Something isn't working non-breaking Non-breaking change labels Nov 10, 2026
@morristai

Copy link
Copy Markdown
Contributor Author

@ChuckHastings thanks for triggering the CI run earlier.

In the previous run on 38d38c2 (run 42732183195), check-style, the C++/Python/wheel builds, wheel tests, and the C API tests (CAPI_SSSP_TEST and CAPI_RANDOM_WALKS_TEST in the passing conda-cpp-tests jobs) all passed. The failures (telemetry-setup, CUDA 13.4 matrix lookups, and devcontainer) were from the branch still being based on an older main from October.

I merged the latest main into the branch. When you have a moment, could you please run /ok to test on the updated commit?

@ChuckHastings

Copy link
Copy Markdown
Collaborator

@morristai - If you can merge with the latest code I will trigger a rerun and try and get this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: cugraph_sssp and cugraph_biased_random_walks segfault on a graph created without weights

2 participants