Skip to content

Conversation

@Schwarf
Copy link
Contributor

@Schwarf Schwarf commented Jul 26, 2025

This PR fixes a crash when writing an empty graph (numberOfNodes() == 0) using NetworkitBinaryWriter.
Closes #909.

Root Cause

When serializing an empty graph, the internal logic attempted to compute offset values based on the number of chunks. However, if nodes == 0, then chunks == 0, and expressions like (chunks - 1) underflowed due to unsigned arithmetic. This led to corrupted headers and potential segmentation faults during read/write operations.

Fix

This PR addresses the issue by:

  • Zero-initializing all uint64_t fields of the header using brace initialization
  • Explicitly handling the empty graph case at the beginning of NetworkitBinaryWriter::writeData():

@Schwarf Schwarf requested a review from angriman July 27, 2025 17:58
angriman
angriman previously approved these changes Jul 29, 2025
@fabratu fabratu merged commit e6f078b into networkit:master Aug 21, 2025
29 checks passed
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.

Segfault writing empty graph in NetworkitBinary format

3 participants