Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit d267d89

Browse files
bosilcaggouaillardet
authored andcommitted
Correctly compute the space needed for the args.
Add checks to bail out if our precomputed value is less than needed (we are already at fault). (cherry picked from commit open-mpi/ompi@16d9f71)
1 parent 402abf9 commit d267d89

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

ompi/datatype/ompi_datatype_args.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2013 The University of Tennessee and The University
6+
* Copyright (c) 2004-2016 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@@ -44,12 +44,12 @@ __ompi_datatype_create_from_args( int32_t* i, OPAL_PTRDIFF_TYPE * a,
4444
ompi_datatype_t** d, int32_t type );
4545

4646
typedef struct __dt_args {
47-
int ref_count;
48-
int create_type;
47+
int32_t ref_count;
48+
int32_t create_type;
4949
size_t total_pack_size;
50-
int ci;
51-
int ca;
52-
int cd;
50+
int32_t ci;
51+
int32_t ca;
52+
int32_t cd;
5353
int* i;
5454
OPAL_PTRDIFF_TYPE* a;
5555
ompi_datatype_t** d;
@@ -71,11 +71,11 @@ typedef struct __dt_args {
7171
#endif /* OPAL_ALIGN_WORD_SIZE_INTEGERS */
7272

7373
/**
74-
* Some architecture require that 64 bits pointers (to pointers) has to
75-
* be 64 bits aligned. As in the ompi_datatype_args_t structure we have 2 such
76-
* pointers and one to an array of ints, if we start by setting the 64
77-
* bits aligned one we will not have any trouble. Problem arise on
78-
* SPARC 64.
74+
* Some architectures require 64 bits pointers (to pointers) to
75+
* be 64 bits aligned. As in the ompi_datatype_args_t structure we have
76+
* 2 such array of pointers and one to an array of ints, if we start by
77+
* setting the 64 bits aligned one we will not have any trouble. Problem
78+
* originally reported on SPARC 64.
7979
*/
8080
#define ALLOC_ARGS(PDATA, IC, AC, DC) \
8181
do { \
@@ -236,9 +236,8 @@ int32_t ompi_datatype_set_args( ompi_datatype_t* pData,
236236
*/
237237
OBJ_RETAIN( d[pos] );
238238
pArgs->total_pack_size += ((ompi_datatype_args_t*)d[pos]->args)->total_pack_size;
239-
} else {
240-
pArgs->total_pack_size += 2 * sizeof(int); /* _NAMED + predefined id */
241239
}
240+
pArgs->total_pack_size += sizeof(int); /* each data has an ID */
242241
}
243242

244243
return OMPI_SUCCESS;
@@ -497,6 +496,12 @@ int ompi_datatype_get_pack_description( ompi_datatype_t* datatype,
497496
__ompi_datatype_pack_description( datatype, &recursive_buffer, &next_index );
498497

499498
if (!ompi_datatype_is_predefined(datatype)) {
499+
/* If the precomputed size is not large enough we're already in troubles, we
500+
* have overwritten outside of the allocated buffer. Raise the alarm !
501+
* If not reassess the size of the packed buffer necessary for holding the
502+
* datatype description.
503+
*/
504+
assert(args->total_pack_size >= (uintptr_t)((char*)recursive_buffer - (char *) packed_description));
500505
args->total_pack_size = (uintptr_t)((char*)recursive_buffer - (char *) packed_description);
501506
}
502507

0 commit comments

Comments
 (0)