[mpich2-dev] [PATCH 1/1] Issue 4120: Add more overflow assertions to datatypes

Jeff Parker jjparker at us.ibm.com
Wed Mar 26 14:24:40 CDT 2008


Added more overflow assertions when MPI_Aints are being added to pointers,
to ensure the result does not overflow the size of a pointer.

Signed-off-by: Jeff Parker <jjparker at us.ibm.com>
---
 lib/mpi/mpich2/src/mpi/datatype/pack.c             |    9 ++++--
 lib/mpi/mpich2/src/mpi/datatype/pack_external.c    |    4 +-
 .../mpich2/src/mpi/datatype/pack_external_size.c   |    2 +-
 lib/mpi/mpich2/src/mpi/datatype/unpack.c           |    9 ++++--
 lib/mpi/mpich2/src/mpi/datatype/unpack_external.c  |    4 +-
 .../src/mpid/common/datatype/dataloop/dataloop.c   |   15 +++++++++
 .../mpid/common/datatype/dataloop/segment_ops.c    |   32 +++++++++++++++++++-
 .../common/datatype/dataloop/typesize_support.c    |   24 +++++++-------
 .../mpich2/src/mpid/common/datatype/mpid_segment.c |    4 ++-
 9 files changed, 78 insertions(+), 25 deletions(-)

diff --git a/lib/mpi/mpich2/src/mpi/datatype/pack.c b/lib/mpi/mpich2/src/mpi/datatype/pack.c
index 7f64e80..d7a27c6 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/pack.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/pack.c
@@ -190,15 +190,18 @@ int MPI_Pack(void *inbuf,
     first = 0;
     last  = SEGMENT_IGNORE_LAST;
 
+    /* Ensure that pointer increment fits in a pointer */
+    MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT outbuf) + (MPI_Aint)*position );
+
     MPID_Segment_pack(segp,
 		      first,
 		      &last,
 		      (void *) ((char *) outbuf + *position));
 
-    /* Ensure that "last" fits into an int datatype. */
-    MPID_Ensure_Aint_fits_in_int( last );
+    /* Ensure that calculation fits into an int datatype. */
+    MPID_Ensure_Aint_fits_in_int( (MPI_Aint)*position + last );
 
-    *position += (int) last;
+    *position = (int)( (MPI_Aint)*position + last );
 
     MPID_Segment_free(segp);
 
diff --git a/lib/mpi/mpich2/src/mpi/datatype/pack_external.c b/lib/mpi/mpich2/src/mpi/datatype/pack_external.c
index 19dbf00..e794c6a 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/pack_external.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/pack_external.c
@@ -134,8 +134,8 @@ int MPI_Pack_external(char *datarep,
     first = 0;
     last  = SEGMENT_IGNORE_LAST;
 
-    /* Ensure that position fits in a pointer */
-    MPID_Ensure_Aint_fits_in_pointer( *position );
+    /* Ensure that pointer increment fits in a pointer */
+    MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT outbuf) + *position );
 
     MPID_Segment_pack_external32(segp,
 				 first,
diff --git a/lib/mpi/mpich2/src/mpi/datatype/pack_external_size.c b/lib/mpi/mpich2/src/mpi/datatype/pack_external_size.c
index ced3c00..dbb60ee 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/pack_external_size.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/pack_external_size.c
@@ -97,7 +97,7 @@ int MPI_Pack_external_size(char *datarep,
 
     /* ... body of routine ... */
     
-    *size = incount * MPID_Datatype_size_external32(datatype);
+    *size = (MPI_Aint)incount * (MPI_Aint)MPID_Datatype_size_external32(datatype);
 
     /* ... end of body of routine ... */
 
diff --git a/lib/mpi/mpich2/src/mpi/datatype/unpack.c b/lib/mpi/mpich2/src/mpi/datatype/unpack.c
index 57cd4b7..cfc5048 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/unpack.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/unpack.c
@@ -133,15 +133,18 @@ int MPI_Unpack(void *inbuf, int insize, int *position,
     first = 0;
     last  = SEGMENT_IGNORE_LAST;
 
+    /* Ensure that pointer increment fits in a pointer */
+    MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT inbuf) + (MPI_Aint)*position );
+
     MPID_Segment_unpack(segp,
 			first,
 			&last,
 			(void *) ((char *) inbuf + *position));
 
-    /* Ensure that "last" fits into an int datatype. */
-    MPID_Ensure_Aint_fits_in_int( last );
+    /* Ensure that calculation fits into an int datatype. */
+    MPID_Ensure_Aint_fits_in_int( (MPI_Aint)*position + last );
 
-    *position += (int) last;
+    *position = (int)( (MPI_Aint)*position + last );
 
     MPID_Segment_free(segp);
 
diff --git a/lib/mpi/mpich2/src/mpi/datatype/unpack_external.c b/lib/mpi/mpich2/src/mpi/datatype/unpack_external.c
index 3a17994..9804cdc 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/unpack_external.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/unpack_external.c
@@ -118,8 +118,8 @@ int MPI_Unpack_external(char *datarep,
     first = 0;
     last  = SEGMENT_IGNORE_LAST;
 
-    /* Ensure that position fits in a pointer */
-    MPID_Ensure_Aint_fits_in_pointer( *position );
+    /* Ensure that pointer increment fits in a pointer */
+    MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT inbuf) + *position );
 
     MPID_Segment_unpack_external32(segp,
 				   first,
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop.c
index c403db4..2eae1dd 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop.c
@@ -152,6 +152,7 @@ void PREPEND_PREFIX(Dataloop_update)(DLOOP_Dataloop *dataloop,
 	     * LHS, so we get this much nastier form instead (using common
 	     * struct for contig and vector): 
 	     */
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.cm_t.dataloop + ptrdiff); 
 	    dataloop->loop_params.cm_t.dataloop = 
 		(DLOOP_Dataloop *) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.cm_t.dataloop + ptrdiff);
@@ -161,9 +162,12 @@ void PREPEND_PREFIX(Dataloop_update)(DLOOP_Dataloop *dataloop,
 	    break;
 
 	case DLOOP_KIND_BLOCKINDEXED:
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.bi_t.offset_array + ptrdiff);
 	    dataloop->loop_params.bi_t.offset_array = 
 		(DLOOP_Offset *) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.bi_t.offset_array + ptrdiff);
+
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.bi_t.dataloop + ptrdiff);
 	    dataloop->loop_params.bi_t.dataloop = 
 		(DLOOP_Dataloop *) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.bi_t.dataloop + ptrdiff);
@@ -173,12 +177,17 @@ void PREPEND_PREFIX(Dataloop_update)(DLOOP_Dataloop *dataloop,
 	    break;
 
 	case DLOOP_KIND_INDEXED:
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.blocksize_array + ptrdiff);
 	    dataloop->loop_params.i_t.blocksize_array = 
 		(DLOOP_Count *) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.blocksize_array + ptrdiff);
+
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.offset_array + ptrdiff);
 	    dataloop->loop_params.i_t.offset_array = 
 		(DLOOP_Offset *) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.offset_array + ptrdiff);
+
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.dataloop + ptrdiff);
 	    dataloop->loop_params.i_t.dataloop = 
 		(DLOOP_Dataloop *) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.dataloop + ptrdiff);
@@ -188,12 +197,17 @@ void PREPEND_PREFIX(Dataloop_update)(DLOOP_Dataloop *dataloop,
 	    break;
 
 	case DLOOP_KIND_STRUCT:
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.blocksize_array + ptrdiff);
 	    dataloop->loop_params.s_t.blocksize_array = 
 		(DLOOP_Count *) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.blocksize_array + ptrdiff);
+
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.offset_array + ptrdiff);
 	    dataloop->loop_params.s_t.offset_array = 
 		(DLOOP_Offset *) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.offset_array + ptrdiff);
+
+	    MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.dataloop_array + ptrdiff);
 	    dataloop->loop_params.s_t.dataloop_array = 
 		(DLOOP_Dataloop **) MPI_AINT_CAST_TO_VOID_PTR
 		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.dataloop_array + ptrdiff);
@@ -201,6 +215,7 @@ void PREPEND_PREFIX(Dataloop_update)(DLOOP_Dataloop *dataloop,
 	    /* fix the N dataloop pointers too */
 	    looparray = dataloop->loop_params.s_t.dataloop_array;
 	    for (i=0; i < dataloop->loop_params.s_t.count; i++) {
+		MPID_Ensure_Aint_fits_in_pointer(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) looparray[i] + ptrdiff);
 		looparray[i] = (DLOOP_Dataloop *) MPI_AINT_CAST_TO_VOID_PTR
 		    (MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) looparray[i] + ptrdiff);
 	    }
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
index 982de22..efa7d31 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
@@ -36,15 +36,20 @@ int PREPEND_PREFIX(Segment_contig_m2m)(DLOOP_Offset *blocks_p,
 #endif
 
     if (paramp->direction == DLOOP_M2M_TO_USERBUF) {
+	/* Ensure that pointer increment fits in a pointer */
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off );
 	memcpy((char *) MPI_AINT_CAST_TO_VOID_PTR ((MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off), 
 	       paramp->streambuf, 
 	       size);
     }
     else {
+	/* Ensure that pointer increment fits in a pointer */
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off );
 	memcpy(paramp->streambuf, 
 	       (char *) ( MPI_AINT_CAST_TO_VOID_PTR ((MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off) ), 
 	       size);
     }
+    MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->streambuf)) + size );
     paramp->streambuf += size;
     return 0;
 }
@@ -70,6 +75,8 @@ int PREPEND_PREFIX(Segment_vector_m2m)(DLOOP_Offset *blocks_p,
     struct PREPEND_PREFIX(m2m_params) *paramp = v_paramp;
     char *cbufp;
 
+    /* Ensure that pointer increment fits in a pointer */
+    MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off );
     cbufp = (char*)( MPI_AINT_CAST_TO_VOID_PTR ( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off ) );
     DLOOP_Handle_get_size_macro(el_type, el_size);
 
@@ -102,11 +109,17 @@ int PREPEND_PREFIX(Segment_vector_m2m)(DLOOP_Offset *blocks_p,
 	else {
 	    for (i=0; i < whole_count; i++) {
 		memcpy(cbufp, paramp->streambuf, ((DLOOP_Offset)blksz) * el_size);
+		MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->streambuf)) + 
+						  ((DLOOP_Offset)blksz) * el_size );
 		paramp->streambuf += ((DLOOP_Offset)blksz) * el_size;
+
+		MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (cbufp)) + stride );
 		cbufp += stride;
 	    }
 	    if (blocks_left) {
 		memcpy(cbufp, paramp->streambuf, ((DLOOP_Offset)blocks_left) * el_size);
+		MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->streambuf)) + 
+						  ((DLOOP_Offset)blocks_left) * el_size );
 		paramp->streambuf += ((DLOOP_Offset)blocks_left) * el_size;
 	    }
 	}
@@ -137,11 +150,15 @@ int PREPEND_PREFIX(Segment_vector_m2m)(DLOOP_Offset *blocks_p,
 	else {
 	    for (i=0; i < whole_count; i++) {
 		memcpy(paramp->streambuf, cbufp, (DLOOP_Offset)blksz * el_size);
+		MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->streambuf)) + 
+						  (DLOOP_Offset)blksz * el_size );
 		paramp->streambuf += (DLOOP_Offset)blksz * el_size;
 		cbufp += stride;
 	    }
 	    if (blocks_left) {
 		memcpy(paramp->streambuf, cbufp, (DLOOP_Offset)blocks_left * el_size);
+		MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->streambuf)) + 
+						  (DLOOP_Offset)blocks_left * el_size );
 		paramp->streambuf += (DLOOP_Offset)blocks_left * el_size;
 	    }
 	}
@@ -174,6 +191,8 @@ int PREPEND_PREFIX(Segment_blkidx_m2m)(DLOOP_Offset *blocks_p,
 
 	DLOOP_Assert(curblock < count);
 
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + 
+					  rel_off + offsetarray[curblock] );
 	cbufp = (char*) MPI_AINT_CAST_TO_VOID_PTR
 	          ((MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + 
 		   rel_off + offsetarray[curblock]);
@@ -207,6 +226,8 @@ int PREPEND_PREFIX(Segment_blkidx_m2m)(DLOOP_Offset *blocks_p,
 	    memcpy(dest, src, (DLOOP_Offset)blocklen * el_size);
 	}
 
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->streambuf)) + 
+					  (DLOOP_Offset)blocklen * el_size );
 	paramp->streambuf += (DLOOP_Offset)blocklen * el_size;
 	blocks_left -= blocklen;
 	curblock++;
@@ -240,6 +261,9 @@ int PREPEND_PREFIX(Segment_index_m2m)(DLOOP_Offset *blocks_p,
 	DLOOP_Assert(curblock < count);
 	cur_block_sz = blockarray[curblock];
 
+	/* Ensure that pointer increment fits in a pointer */
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + 
+					  rel_off + offsetarray[curblock]);
 	cbufp = (char*) MPI_AINT_CAST_TO_VOID_PTR
 	          ((MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + 
 		   rel_off + offsetarray[curblock]);
@@ -273,6 +297,8 @@ int PREPEND_PREFIX(Segment_index_m2m)(DLOOP_Offset *blocks_p,
 	    memcpy(dest, src, cur_block_sz * el_size);
 	}
 
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->streambuf)) + 
+					  cur_block_sz * el_size );
 	paramp->streambuf += cur_block_sz * el_size;
 	blocks_left -= cur_block_sz;
 	curblock++;
@@ -582,10 +608,12 @@ static int DLOOP_Segment_contig_mpi_flatten(DLOOP_Offset *blocks_p,
     
     last_idx = paramp->index - 1;
     if (last_idx >= 0) {
+	MPID_Ensure_Aint_fits_in_pointer( paramp->disps[last_idx] + ((DLOOP_Offset)paramp->blklens[last_idx]) );
 	last_end = (char*) MPI_AINT_CAST_TO_VOID_PTR 
 	           (paramp->disps[last_idx] + ((DLOOP_Offset)paramp->blklens[last_idx]));
     }
 
+    MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (bufp)) + rel_off);
     if ((last_idx == paramp->length-1) &&
 	(last_end != ((char *) bufp + rel_off)))
     {
@@ -670,10 +698,12 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
 
 	last_idx = paramp->index - 1;
 	if (last_idx >= 0) {
+	    MPID_Ensure_Aint_fits_in_pointer( paramp->disps[last_idx] + ((DLOOP_Offset)paramp->blklens[last_idx]) );
 	    last_end = (char*) MPI_AINT_CAST_TO_VOID_PTR 
 		       (paramp->disps[last_idx] + ((DLOOP_Offset)paramp->blklens[last_idx]));
 	}
 
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp) + rel_off );
 	if ((last_idx == paramp->length-1) &&
 	    (last_end != ((char *) bufp + rel_off)))
 	{
@@ -697,7 +727,7 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
 	    paramp->blklens[last_idx] += size;
 	}
 	else {
-	    paramp->disps[last_idx+1]   = MPI_VOID_PTR_CAST_TO_MPI_AINT ((char *) bufp + rel_off);
+	    paramp->disps[last_idx+1]   = (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp) + rel_off;
 	    paramp->blklens[last_idx+1] = size;
 	    paramp->index++;
 	}
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/typesize_support.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/typesize_support.c
index 4a3dc60..88a2bc4 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/typesize_support.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/typesize_support.c
@@ -256,15 +256,15 @@ void PREPEND_PREFIX(Type_calc_footprint)(MPI_Datatype type,
 					tfp->lb, tfp->ub);
 	    tfp->true_lb = tfp->lb + (true_lb - lb);
 	    tfp->true_ub = tfp->ub + (true_ub - ub);
-	    tfp->size    = ints[0] * size;
+	    tfp->size    = (DLOOP_Offset)ints[0] * size;
 	    tfp->extent  = tfp->ub - tfp->lb;
 	    break;
 	case MPI_COMBINER_VECTOR:
 	case MPI_COMBINER_HVECTOR:
 	case MPI_COMBINER_HVECTOR_INTEGER:
-	    if (combiner == MPI_COMBINER_VECTOR) stride = ints[2] * extent;
+	    if (combiner == MPI_COMBINER_VECTOR) stride = (DLOOP_Offset)ints[2] * extent;
 	    else if (combiner == MPI_COMBINER_HVECTOR) stride = aints[0];
-	    else /* HVECTOR_INTEGER */ stride = ints[2];
+	    else /* HVECTOR_INTEGER */ stride = (DLOOP_Offset)ints[2];
 
 	    DLOOP_DATATYPE_VECTOR_LB_UB(ints[0] /* count */,
 					stride /* stride in bytes */,
@@ -273,25 +273,25 @@ void PREPEND_PREFIX(Type_calc_footprint)(MPI_Datatype type,
 					tfp->lb, tfp->ub);
 	    tfp->true_lb = tfp->lb + (true_lb - lb);
 	    tfp->true_ub = tfp->ub + (true_ub - ub);
-	    tfp->size    = ints[0] * ints[1] * size;
+	    tfp->size    = (DLOOP_Offset)ints[0] * (DLOOP_Offset)ints[1] * size;
 	    tfp->extent  = tfp->ub - tfp->lb;
 	    break;
 	case MPI_COMBINER_INDEXED_BLOCK:
 	    /* prime min_lb and max_ub */
 	    DLOOP_DATATYPE_BLOCK_LB_UB(ints[1] /* blklen */,
-				       ints[2] * extent /* disp */,
+				       (DLOOP_Offset)ints[2] * extent /* disp */,
 				       lb, ub, extent,
 				       min_lb, max_ub);
 
 	    for (i=1; i < ints[0]; i++) {
 		DLOOP_DATATYPE_BLOCK_LB_UB(ints[1] /* blklen */,
-					   ints[i+2] * extent /* disp */,
+					   (DLOOP_Offset)ints[i+2] * extent /* disp */,
 					   lb, ub, extent,
 					   tmp_lb, tmp_ub);
 		if (tmp_lb < min_lb) min_lb = tmp_lb;
 		if (tmp_ub > max_ub) max_ub = tmp_ub;
 	    }
-	    tfp->size    = ints[0] * ints[1] * size;
+	    tfp->size    = (DLOOP_Offset)ints[0] * (DLOOP_Offset)ints[1] * size;
 	    tfp->lb      = min_lb;
 	    tfp->ub      = max_ub;
 	    tfp->true_lb = min_lb + (true_lb - lb);
@@ -312,9 +312,9 @@ void PREPEND_PREFIX(Type_calc_footprint)(MPI_Datatype type,
 		/* prime min_lb, max_ub, count */
 		ntypes = ints[i+1];
 		if (combiner == MPI_COMBINER_INDEXED)
-		    disp = ints[ints[0]+i+1] * extent;
+		    disp = (DLOOP_Offset)ints[ints[0]+i+1] * extent;
 		else if (combiner == MPI_COMBINER_HINDEXED_INTEGER)
-		    disp = ints[ints[0]+i+1];
+		    disp = (DLOOP_Offset)ints[ints[0]+i+1];
 		else /* MPI_COMBINER_HINDEXED */
 		    disp = aints[i];
 
@@ -329,9 +329,9 @@ void PREPEND_PREFIX(Type_calc_footprint)(MPI_Datatype type,
 
 		    ntypes += ints[i+1];
 		    if (combiner == MPI_COMBINER_INDEXED)
-			disp = ints[ints[0]+i+1] * extent;
+			disp = (DLOOP_Offset)ints[ints[0]+i+1] * extent;
 		    else if (combiner == MPI_COMBINER_HINDEXED_INTEGER)
-			disp = ints[ints[0]+i+1];
+			disp = (DLOOP_Offset)ints[ints[0]+i+1];
 		    else /* MPI_COMBINER_HINDEXED */
 			disp = aints[i];
 
@@ -460,7 +460,7 @@ static void DLOOP_Type_calc_footprint_struct(MPI_Datatype type,
 
 	tmp_true_lb = tmp_lb + (true_lb - lb);
 	tmp_true_ub = tmp_ub + (true_ub - ub);
-	tmp_size += size * ints[i+1];
+	tmp_size += size * (DLOOP_Offset)ints[i+1];
 
 	if (combiner == MPI_COMBINER_NAMED) {
 	    /* NOTE: This is a special case. If a user creates a struct
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_segment.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_segment.c
index fd00e76..e478949 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_segment.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_segment.c
@@ -247,7 +247,8 @@ static int MPID_Segment_contig_pack_to_iov(DLOOP_Offset *blocks_p,
 	last_end = ((char *) paramp->u.pack_vector.vectorp[last_idx].DLOOP_VECTOR_BUF) +
 	    paramp->u.pack_vector.vectorp[last_idx].DLOOP_VECTOR_LEN;
     }
-
+    
+    MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (bufp)) + rel_off );
     if ((last_idx == paramp->u.pack_vector.length-1) &&
 	(last_end != ((char *) bufp + rel_off)))
     {
@@ -345,6 +346,7 @@ static int MPID_Segment_vector_pack_to_iov(DLOOP_Offset *blocks_p,
 		paramp->u.pack_vector.vectorp[last_idx].DLOOP_VECTOR_LEN;
 	}
 
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT (bufp)) + rel_off );
 	if ((last_idx == paramp->u.pack_vector.length-1) &&
 	    (last_end != ((char *) bufp + rel_off)))
 	{
-- 
1.5.3.7




More information about the mpich2-dev mailing list