Skip to content

[Fix] Provided MPI_type_get_content array sizes may exceed actual ones, do not use them #13131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ompi/mpi/c/type_get_contents.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2025 BULL S.A.S. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -45,7 +46,7 @@ int MPI_Type_get_contents(MPI_Datatype mtype,
MPI_Aint array_of_addresses[],
MPI_Datatype array_of_datatypes[])
{
int rc, i;
int rc, i, type_code;
MPI_Datatype newtype;

MEMCHECKER(
Expand All @@ -65,6 +66,13 @@ int MPI_Type_get_contents(MPI_Datatype mtype,
}
}

/* Counts may exceed actual ones, we have no choice but to recompute them */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand that comment: what are the actual ones? The count argument the user provided? Or the

Suggested change
/* Counts may exceed actual ones, we have no choice but to recompute them */
/* Counts may exceed the user-provided counts, we have no choice but to recompute them */

rc = ompi_datatype_get_args(mtype, 0, &max_integers, NULL, &max_addresses, NULL, &max_datatypes,
NULL, &type_code);
if (rc != MPI_SUCCESS) {
OMPI_ERRHANDLER_RETURN(MPI_ERR_INTERN, MPI_COMM_WORLD, MPI_ERR_INTERN, FUNC_NAME);
}

Comment on lines +70 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of querying the sizes if we don't act on that information? If the user told us the arrays are of a certain size and the type requires more then we should error out, raising MPI_ERR_ARG.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This updates the user provided max lengths before passing them to ompi_datatype_get_args. As if ompi_datatype_get_args was not correctly handling the case where user provides more space than required (which is not the case as I pointed in my prior comment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be worried about the converse: the user provides insufficient space and we write past the bounds of the user buffer. That is what I thought this patch addressed. Otherwise I don't see what this patch accomplishes.

rc = ompi_datatype_get_args( mtype, 1, &max_integers, array_of_integers,
&max_addresses, array_of_addresses,
&max_datatypes, array_of_datatypes, NULL );
Expand Down