Skip to content

Commit 4b60260

Browse files
[Fix] Provided MPI_type_get_content array sizes may exceed actual ones, do not use them
MPI 4.1 specifications, page 166, lines 24-27: The values given for max_integers, max_addresses, max_large_counts, and max_datatypes must be at least as large as the value returned in num_integers, num_addresses, num_large_counts, and num_datatypes, respectively, in the call MPI_TYPE_GET_ENVELOPE for the same datatype argument. Signed-off-by: Brelle Emmanuel <[email protected]>
1 parent 8a64826 commit 4b60260

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ompi/mpi/c/type_get_contents.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2015 Research Organization for Information Science
1313
* and Technology (RIST). All rights reserved.
14+
* Copyright (c) 2025 BULL S.A.S. All rights reserved.
1415
* $COPYRIGHT$
1516
*
1617
* Additional copyrights may follow
@@ -45,7 +46,7 @@ int MPI_Type_get_contents(MPI_Datatype mtype,
4546
MPI_Aint array_of_addresses[],
4647
MPI_Datatype array_of_datatypes[])
4748
{
48-
int rc, i;
49+
int rc, i, type_code;
4950
MPI_Datatype newtype;
5051

5152
MEMCHECKER(
@@ -65,6 +66,13 @@ int MPI_Type_get_contents(MPI_Datatype mtype,
6566
}
6667
}
6768

69+
/* Counts may exceed actual ones, we have no choice but to recompute them */
70+
rc = ompi_datatype_get_args(mtype, 0, &max_integers, NULL, &max_addresses, NULL, &max_datatypes,
71+
NULL, &type_code);
72+
if (rc != MPI_SUCCESS) {
73+
OMPI_ERRHANDLER_RETURN(MPI_ERR_INTERN, MPI_COMM_WORLD, MPI_ERR_INTERN, FUNC_NAME);
74+
}
75+
6876
rc = ompi_datatype_get_args( mtype, 1, &max_integers, array_of_integers,
6977
&max_addresses, array_of_addresses,
7078
&max_datatypes, array_of_datatypes, NULL );

0 commit comments

Comments
 (0)