Skip to content

Commit 792df5f

Browse files
committed
Throw exception if counter exceeds what MPI read can read at once.
1 parent 3291a36 commit 792df5f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

include/gdsb/mpi_graph_io.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ void all_read_binary_graph_batch(MPI_File const input,
151151
throw std::runtime_error("Could not seek to specified offset [" + std::to_string(offset) + "] within MPI file.");
152152
}
153153

154+
if (count > std::numeric_limits<int>::max())
155+
{
156+
throw std::runtime_error("Count of edges exceeds MPI read count type maximum.");
157+
}
158+
154159
MPI_Status status;
155160
int const read_all_error = MPI_File_read_all(input, edges, count, mpi_datatype, &status);
156161
if (read_all_error != MPI_SUCCESS)

test/mpi_graph_io_tests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,4 +991,33 @@ TEST_CASE("MPI, all_read_binary_graph_batch, batch for batch")
991991
CHECK((edges[idx].source == 33 && edges[idx++].target == 37));
992992
CHECK((edges[idx].source == 34 && edges[idx++].target == 37));
993993
CHECK((edges[idx].source == 35 && edges[idx++].target == 37));
994+
}
995+
996+
TEST_CASE("MPI, all_read_binary_graph_batch, read issues")
997+
{
998+
std::filesystem::path file_path(graph_path + directed_unweighted_graph_enzymes_bin);
999+
mpi::FileWrapper binary_graph{ file_path };
1000+
1001+
BinaryGraphHeader header = mpi::read_binary_graph_header(binary_graph.get());
1002+
REQUIRE(header.vertex_id_byte_size == sizeof(Vertex32));
1003+
REQUIRE(header.directed);
1004+
REQUIRE(!header.weighted);
1005+
REQUIRE(!header.dynamic);
1006+
1007+
mpi::MPIEdge32 mpi_edge_t;
1008+
1009+
SECTION("Read Success")
1010+
{
1011+
Edges32 edges(header.edge_count);
1012+
mpi::all_read_binary_graph_batch(binary_graph.get(), header, &(edges[0]), sizeof(Edge32), 0, header.edge_count,
1013+
mpi_edge_t.get());
1014+
}
1015+
1016+
SECTION("Read exceeds counter")
1017+
{
1018+
Edges32 edges(header.edge_count);
1019+
uint64_t count = std::numeric_limits<uint32_t>::max();
1020+
CHECK_THROWS(mpi::all_read_binary_graph_batch(binary_graph.get(), header, &(edges[0]), sizeof(Edge32), 0, count,
1021+
mpi_edge_t.get()));
1022+
}
9941023
}

0 commit comments

Comments
 (0)