Skip to content

Commit d38fe29

Browse files
committed
c bindings: add protection for big count
when using internal ompi interfaces which can't handle count > INT_MAX. Signed-off-by: Howard Pritchard <howardp@lanl.gov>
1 parent b56439a commit d38fe29

17 files changed

+111
-23
lines changed

ompi/mpi/c/bindings.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ BEGIN_C_DECLS
104104
} \
105105
} while (0)
106106

107+
108+
/* check for integer overflow - needed while parts of Open MPI have not been embiggened */
109+
#define OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(RC, x) \
110+
do { \
111+
if ((x) > INT_MAX) { \
112+
(RC) = MPI_ERR_VALUE_TOO_LARGE; \
113+
} else { \
114+
(RC) = MPI_SUCCESS; \
115+
} \
116+
} while (0)
117+
118+
107119
END_C_DECLS
108120

109121
#endif /* OMPI_C_BINDINGS_H */

ompi/mpi/c/file_get_type_extent.c.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ PROTOTYPE ERROR_CLASS file_get_type_extent(FILE fh, DATATYPE datatype,
5858

5959
switch (fh->f_io_version) {
6060
case MCA_IO_BASE_V_3_0_0:
61-
/* TODO:BIGCOUNT: Need to update below code with bigcount variant */
6261
rc = fh->f_io_selected_module.v3_0_0.
6362
io_module_file_get_type_extent(fh, datatype, &tmp_extent);
6463
*extent = tmp_extent;

ompi/mpi/c/pack_external.c.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ PROTOTYPE ERROR_CLASS pack_external(STRING datarep, BUFFER inbuf, COUNT incount,
5858
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
5959
OMPI_CHECK_USER_BUFFER(rc, inbuf, datatype, incount);
6060
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
61+
#if OMPI_BIGCOUNT_SRC
62+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, incount);
63+
if (MPI_SUCCESS != rc) {
64+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
65+
}
66+
#endif
6167
}
6268

63-
/* TODO:BIGCOUNT: Update ompi_datatype_pack_external for bigcount */
64-
6569
rc = ompi_datatype_pack_external(datarep, inbuf, incount,
6670
datatype, outbuf,
6771
outsize, (MPI_Aint *)position);

ompi/mpi/c/pack_external_size.c.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ PROTOTYPE ERROR_CLASS pack_external_size(STRING datarep, COUNT incount,
5151
} else if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
5252
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_TYPE, FUNC_NAME);
5353
}
54+
#if OMPI_BIGCOUNT_SRC
55+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, incount);
56+
if (MPI_SUCCESS != rc) {
57+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
58+
}
59+
#endif
5460
}
5561

56-
/* TODO:BIGCOUNT: Update when the ompi_datatype code is updated for bigcount */
5762
rc = ompi_datatype_pack_external_size(datarep, (int) incount,
5863
datatype, &tmp_size);
5964
*size = tmp_size;

ompi/mpi/c/type_contiguous.c.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ PROTOTYPE ERROR_CLASS type_contiguous(COUNT count,
5050
} else if( count < 0 ) {
5151
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_COUNT, FUNC_NAME);
5252
}
53+
#if OMPI_BIGCOUNT_SRC
54+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, count);
55+
if (OMPI_SUCCESS != rc) {
56+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
57+
}
58+
#endif
5359
}
5460

5561
rc = ompi_datatype_create_contiguous( count, oldtype, newtype );
5662
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME );
5763

5864
/* data description */
5965
{
60-
/* TODO:BIGCOUNT: need to embiggen ompi_datatype_set_args */
6166
#if OMPI_BIGCOUNT_SRC
6267
int icount = (int)count;
6368
const int* a_i[1] = {&icount};

ompi/mpi/c/type_create_darray.c.in

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ PROTOTYPE ERROR_CLASS type_create_darray(INT size,
6969
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_ARG, FUNC_NAME);
7070
}
7171
if( ndims > 0 ) {
72+
#if OMPI_BIGCOUNT_SRC
73+
for( i = 0; i < ndims; i++ ) {
74+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, gsize_array[i]);
75+
if (OMPI_SUCCESS != rc) {
76+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
77+
}
78+
}
79+
#endif
7280
for( i = 0; i < ndims; i++ ) {
7381
if( (MPI_DISTRIBUTE_BLOCK != distrib_array[i]) &&
7482
(MPI_DISTRIBUTE_CYCLIC != distrib_array[i]) &&
@@ -90,9 +98,6 @@ PROTOTYPE ERROR_CLASS type_create_darray(INT size,
9098
}
9199
}
92100

93-
/* TODO:BIGCOUNT: need to embiggen ompi_datatype_create_array and
94-
* ompi_datatype_set_args.
95-
*/
96101
#if OMPI_BIGCOUNT_SRC
97102
igsize_array = (int *)malloc(ndims * sizeof(int));
98103
if (NULL == igsize_array) {

ompi/mpi/c/type_create_hindexed.c.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,14 @@ PROTOTYPE ERROR_CLASS type_create_hindexed(COUNT count,
6767
FUNC_NAME );
6868
}
6969
}
70+
#if OMPI_BIGCOUNT_SRC
71+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, count);
72+
if (OMPI_SUCCESS != rc) {
73+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
74+
}
75+
#endif
7076
}
7177

72-
/* TODO:BIGCOUNT: need to embiggen ompi_datatype_create_hindexed, etc. */
7378
#if OMPI_BIGCOUNT_SRC
7479
iarray_of_blocklengths = (int *)malloc(count * sizeof(int));
7580
if (NULL == iarray_of_blocklengths) {

ompi/mpi/c/type_create_hindexed_block.c.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ PROTOTYPE ERROR_CLASS type_create_hindexed_block(COUNT count,
5151
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_TYPE,
5252
FUNC_NAME );
5353
}
54+
#if OMPI_BIGCOUNT_SRC
55+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, count);
56+
if (OMPI_SUCCESS != rc) {
57+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
58+
}
59+
#endif
5460
}
5561

56-
/* TODO:BIGCOUNT: Need to embiggen ompi_datatype_create_hindexed_block */
5762
#if OMPI_BIGCOUNT_SRC
5863
iarray_of_displacements = (MPI_Aint *)malloc(count * sizeof(MPI_Aint));
5964
if (NULL == iarray_of_displacements) {

ompi/mpi/c/type_create_hvector.c.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ PROTOTYPE ERROR_CLASS type_create_hvector(COUNT count,
5757
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_TYPE,
5858
FUNC_NAME );
5959
}
60+
#if OMPI_BIGCOUNT_SRC
61+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, count);
62+
if (OMPI_SUCCESS != rc) {
63+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
64+
}
65+
#endif
6066
}
6167

62-
/* TODO:BIGCOUNT: need to embiggen ompi_datatype_create_hvector */
63-
6468
rc = ompi_datatype_create_hvector ( count, blocklength, stride, oldtype,
6569
newtype );
6670
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME );

ompi/mpi/c/type_create_subarray.c.in

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ PROTOTYPE ERROR_CLASS type_create_subarray(INT ndims,
6262
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_ARG, FUNC_NAME);
6363
}
6464
for( i = 0; i < ndims; i++ ) {
65+
#if OMPI_BIGCOUNT_SRC
66+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, size_array[i]);
67+
if (OMPI_SUCCESS != rc) {
68+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
69+
}
70+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, subsize_array[i]);
71+
if (OMPI_SUCCESS != rc) {
72+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
73+
}
74+
OMPI_CHECK_MPI_COUNT_INT_CONVERSION_OVERFLOW(rc, start_array[i]);
75+
if (OMPI_SUCCESS != rc) {
76+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(rc, FUNC_NAME);
77+
}
78+
#endif
6579
if( (subsize_array[i] < 1) || (subsize_array[i] > size_array[i]) ) {
6680
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_ARG, FUNC_NAME);
6781
} else if( (start_array[i] < 0) || (start_array[i] > (size_array[i] - subsize_array[i])) ) {
@@ -70,8 +84,6 @@ PROTOTYPE ERROR_CLASS type_create_subarray(INT ndims,
7084
}
7185
}
7286

73-
/* TODO:BIGCOUNT: Need to embiggen ompi_datatype_create_subarray */
74-
7587
#if OMPI_BIGCOUNT_SRC
7688
isize_array = (int *)malloc(ndims * sizeof(int));
7789
if (NULL == isize_array) {

0 commit comments

Comments
 (0)