From 2d25f3801b1cdcb4612318d3658d693d79d0d5e2 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 2 Jan 2026 00:16:49 -0500 Subject: [PATCH 1/2] ENH: Bound the field-modification helpers by the destination size modify_all_fields() and modify_field() wrote into a caller-supplied buffer at an offset taken from the field table, with no way to check that the write stayed inside it. Both now take the buffer size, and modify_field() rejects a field whose offset plus size * len exceeds it. The check sits ahead of the switch, so it covers every write path rather than the string case alone, and it reports and returns like the other failures in the function; an assert() would compile away in the release builds that ship. No field table can trip it today: check_total_size() already requires the offsets to tile the structure exactly. It bounds future edits to them. (cherry picked from commit 7356eb146fc1d33ef10e18889f12fcb6c2477440) --- nifti2/nifti_tool.c | 22 ++++++++++++++++------ nifti2/nifti_tool.h | 4 ++-- niftilib/nifti1_tool.c | 20 +++++++++++++++----- niftilib/nifti1_tool.h | 4 ++-- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/nifti2/nifti_tool.c b/nifti2/nifti_tool.c index fdde86f6..d92c5da8 100644 --- a/nifti2/nifti_tool.c +++ b/nifti2/nifti_tool.c @@ -3344,7 +3344,7 @@ int act_mod_hdrs( nt_opts * opts ) } /* okay, let's actually trash the data fields */ - if( modify_all_fields(nhdr, opts, g_hdr1_fields, NT_HDR1_NUM_FIELDS) ) + if( modify_all_fields(nhdr, sizeof(*nhdr), opts, g_hdr1_fields, NT_HDR1_NUM_FIELDS) ) { free(nhdr); return 1; @@ -3470,7 +3470,7 @@ int act_mod_hdr2s( nt_opts * opts ) } /* okay, let's actually trash the data fields */ - if( modify_all_fields(nhdr, opts, g_hdr2_fields, NT_HDR2_NUM_FIELDS) ) + if( modify_all_fields(nhdr, sizeof(*nhdr), opts, g_hdr2_fields, NT_HDR2_NUM_FIELDS) ) { free(nhdr); return 1; @@ -3707,7 +3707,7 @@ int act_mod_nims( nt_opts * opts ) opts->flist.len, opts->infiles.list[filec]); /* okay, let's actually trash the data fields */ - if( modify_all_fields(nim, opts, g_nim2_fields, NT_NIM_NUM_FIELDS) ) + if( modify_all_fields(nim, sizeof(*nim), opts, g_nim2_fields, NT_NIM_NUM_FIELDS) ) { nifti_image_free(nim); return 1; @@ -3810,7 +3810,7 @@ int write_hdr2_to_file( nifti_2_header * nhdr, const char * fname ) /*---------------------------------------------------------------------- * modify all fields in the list *----------------------------------------------------------------------*/ -int modify_all_fields( void * basep, nt_opts * opts, field_s * fields, int flen) +int modify_all_fields( void * basep, size_t baselen, nt_opts * opts, field_s * fields, int flen) { field_s * fp; int fc, lc; /* field and list counters */ @@ -3840,7 +3840,7 @@ int modify_all_fields( void * basep, nt_opts * opts, field_s * fields, int flen) return 1; } - if( modify_field( basep, fp, opts->vlist.list[lc]) ) + if( modify_field( basep, baselen, fp, opts->vlist.list[lc]) ) return 1; } @@ -3853,7 +3853,7 @@ int modify_all_fields( void * basep, nt_opts * opts, field_s * fields, int flen) * * pointer fields are not allowed here *----------------------------------------------------------------------*/ -int modify_field(void * basep, field_s * field, const char * data) +int modify_field(void * basep, size_t baselen, field_s * field, const char * data) { float fval; const char * posn = data; @@ -3870,6 +3870,16 @@ int modify_field(void * basep, field_s * field, const char * data) return 1; } + /* every case below writes field->len elements at field->offset */ + if( field->offset < 0 || field->size < 0 || field->len < 0 || + (size_t)field->offset + (size_t)field->size * (size_t)field->len > baselen ) + { + fprintf(stderr,"** field '%s' (offset %d, %d x %d bytes) does not fit " + "in a %zu byte structure\n", + field->name, field->offset, field->len, field->size, baselen); + return 1; + } + switch( field->type ) { case DT_UNKNOWN: diff --git a/nifti2/nifti_tool.h b/nifti2/nifti_tool.h index ba57369d..b93d115e 100644 --- a/nifti2/nifti_tool.h +++ b/nifti2/nifti_tool.h @@ -306,8 +306,8 @@ NI2_API int fill_hdr2_field_array(field_s * nh_fields); NI2_API int fill_nim1_field_array(field_s * nim_fields); NI2_API int fill_nim2_field_array(field_s * nim_fields); NI2_API int fill_ana_field_array(field_s * ah_fields); -NI2_API int modify_all_fields(void *basep, nt_opts *opts, field_s *fields, int flen); -NI2_API int modify_field (void * basep, field_s * field, const char * data); +NI2_API int modify_all_fields(void *basep, size_t baseplen, nt_opts *opts, field_s *fields, int flen); +NI2_API int modify_field (void * basep, size_t baseplen, field_s * field, const char * data); NI2_API int process_opts (int argc, const char * argv[], nt_opts * opts); NI2_API int remove_ext_list (nifti_image * nim, const char ** elist, int len); NI2_API int usage (const char * prog, int level); diff --git a/niftilib/nifti1_tool.c b/niftilib/nifti1_tool.c index 5d9f89a6..129e8cad 100644 --- a/niftilib/nifti1_tool.c +++ b/niftilib/nifti1_tool.c @@ -2592,7 +2592,7 @@ int act_mod_hdrs( nt_opts * opts ) } /* okay, let's actually trash the data fields */ - if( modify_all_fields(nhdr, opts, g_hdr_fields, NT_HDR_NUM_FIELDS) ) + if( modify_all_fields(nhdr, sizeof(*nhdr), opts, g_hdr_fields, NT_HDR_NUM_FIELDS) ) { free(nhdr); return 1; @@ -2796,7 +2796,7 @@ int act_mod_nims( nt_opts * opts ) opts->flist.len, opts->infiles.list[filec]); /* okay, let's actually trash the data fields */ - if( modify_all_fields(nim, opts, g_nim_fields, NT_NIM_NUM_FIELDS) ) + if( modify_all_fields(nim, sizeof(*nim), opts, g_nim_fields, NT_NIM_NUM_FIELDS) ) { nifti_image_free(nim); return 1; @@ -2866,7 +2866,7 @@ int write_hdr_to_file( nifti_1_header * nhdr, const char * fname ) /*---------------------------------------------------------------------- * modify all fields in the list *----------------------------------------------------------------------*/ -int modify_all_fields( void * basep, nt_opts * opts, field_s * fields, int flen) +int modify_all_fields( void * basep, size_t baselen, nt_opts * opts, field_s * fields, int flen) { field_s * fp; int fc, lc; /* field and list counters */ @@ -2892,7 +2892,7 @@ int modify_all_fields( void * basep, nt_opts * opts, field_s * fields, int flen) return 1; } - if( modify_field( basep, fp, opts->vlist.list[lc]) ) + if( modify_field( basep, baselen, fp, opts->vlist.list[lc]) ) return 1; } @@ -2905,7 +2905,7 @@ int modify_all_fields( void * basep, nt_opts * opts, field_s * fields, int flen) * * pointer fields are not allowed here *----------------------------------------------------------------------*/ -int modify_field(void * basep, field_s * field, const char * data) +int modify_field(void * basep, size_t baselen, field_s * field, const char * data) { float fval; const char * posn = data; @@ -2922,6 +2922,16 @@ int modify_field(void * basep, field_s * field, const char * data) return 1; } + /* every case below writes field->len elements at field->offset */ + if( field->offset < 0 || field->size < 0 || field->len < 0 || + (size_t)field->offset + (size_t)field->size * (size_t)field->len > baselen ) + { + fprintf(stderr,"** field '%s' (offset %d, %d x %d bytes) does not fit " + "in a %zu byte structure\n", + field->name, field->offset, field->len, field->size, baselen); + return 1; + } + switch( field->type ) { case DT_UNKNOWN: diff --git a/niftilib/nifti1_tool.h b/niftilib/nifti1_tool.h index b099924a..ef8e2e98 100644 --- a/niftilib/nifti1_tool.h +++ b/niftilib/nifti1_tool.h @@ -140,8 +140,8 @@ int fill_field (field_s *fp, int type, int offset, int num, const char *na int fill_hdr_field_array(field_s * nh_fields); int fill_nim_field_array(field_s * nim_fields); int fill_ana_field_array(field_s * ah_fields); -int modify_all_fields(void *basep, nt_opts *opts, field_s *fields, int flen); -int modify_field (void * basep, field_s * field, const char * data); +int modify_all_fields(void *basep, size_t baseplen, nt_opts *opts, field_s *fields, int flen); +int modify_field (void * basep, size_t baseplen, field_s * field, const char * data); int process_opts (int argc, const char * argv[], nt_opts * opts); int remove_ext_list (nifti_image * nim, const char ** elist, int len); int usage (const char * prog, int level); From 3095b44b6e16e3af28e1bed43699a32cd890af72 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Fri, 14 Aug 2026 23:30:44 -0400 Subject: [PATCH 2/2] BUG: Fix 64-to-32 bit truncations, including a real overflow in fslio 31 -Wshorten-64-to-32 warnings. Most were benign; one was not. FslSeekVolume() declared `int offset` and assigned it a byte position into the image file: offset = fslio->niftiptr->iname_offset + vols * FslGetVolSize(fslio) * fslio->niftiptr->nbyper; return znzseek(fslio->fileptr, offset, SEEK_SET); Seek to any volume past 2GB and the multiplication overflows, so znzseek -- which takes a 64-bit znz_off_t -- receives a wrong and quite possibly negative position. offset is a local, so widening it to znz_off_t and widening the operands changes no interface. FslReadVolumes' volbytes had the same shape and is now size_t. The rest fall into two groups. Internal helpers were widened to carry the value they were already being handed: nifti_read_extensions() and rci_alloc_mem() now return int64_t rather than truncating their own results, and nifti_read_next_extension() and nifti_check_extension() take an int64_t `remain`. nt_read_bricks(), declared in the uninstalled nifti_tool.h, takes an int64_t length. Where the narrowing target is an installed prototype it can only be made explicit, so each such cast carries a note: nifti_image_load_bricks() returning a brick count as int, nifti_read_subregion_image() returning a byte count as int, nifti_read_ascii_image() taking an int header length, and FslSeekVolume()'s int return. The remainder are strlen() results assigned to int and fread()/znzread() counts, bounded by buffers a few hundred bytes long. Two format strings were widened to PRId64 to match the parameters that changed. (cherry picked from commit 08c5f809210697697e5d83196ec1fde1af05c0c7) --- cifti/afni_xml.c | 8 ++++---- cifti/afni_xml_io.c | 4 ++-- fsliolib/fslio.c | 37 +++++++++++++++++++------------------ nifti2/nifti2_io.c | 25 +++++++++++++------------ nifti2/nifti_tool.c | 8 ++++---- nifti2/nifti_tool.h | 2 +- niftilib/nifti1_io.c | 8 ++++++-- 7 files changed, 49 insertions(+), 43 deletions(-) diff --git a/cifti/afni_xml.c b/cifti/afni_xml.c index 35a7f64a..5a92738a 100644 --- a/cifti/afni_xml.c +++ b/cifti/afni_xml.c @@ -196,7 +196,7 @@ afni_xml_list axml_read_file(const char * fname, int read_data) { if( reset_xml_buf(xd, &buf, &bsize) ) break; - blen = fread(buf, 1, (size_t)bsize, fp); + blen = (unsigned)fread(buf, 1, (size_t)bsize, fp); /* check for early termination */ bshort = loc_strnlen(buf, blen); @@ -285,7 +285,7 @@ afni_xml_list axml_read_buf(const char * buf_in, int64_t bin_len) /* decide how much to copy and copy */ if( bin_remain >= bsize ) blen = (unsigned)bsize; - else blen = bin_remain; + else blen = (unsigned)bin_remain; if(blen > 0 && blen <= (unsigned)bsize) { memcpy(buf, bin_ptr, blen); @@ -900,7 +900,7 @@ static char * strip_whitespace(const char * str, int slen) /* if string is long, forget it */ if( !str || slen > 1024 ) return (char *)str; - len = strlen(str); + len = (int)strlen(str); if( slen > 0 && slen < len ) len = slen; if( len <= 0 ) return (char *)str; @@ -994,7 +994,7 @@ static int disp_gen_text(afni_xml_control * xd, const char * header, if( len == wlen ) { str = "whitespace"; /* just note the whitespace */ - len = strlen(str); + len = (int)strlen(str); } show_depth(xd, 1); diff --git a/cifti/afni_xml_io.c b/cifti/afni_xml_io.c index ce60483b..bcd7d4da 100644 --- a/cifti/afni_xml_io.c +++ b/cifti/afni_xml_io.c @@ -136,7 +136,7 @@ int axio_num_tokens(const char * str, int64_t maxlen) } } - return ntok; + return (int)ntok; } @@ -165,7 +165,7 @@ int axio_show_attrs(FILE * fp, afni_xml_t * ax, int indent) if( !ax ) return 1; for( ind = 0, maxl = 1; ind < ax->attrs.length; ind++ ) { - slen = strlen(ax->attrs.name[ind]); + slen = (int)strlen(ax->attrs.name[ind]); if( slen > maxl ) maxl = slen; } diff --git a/fsliolib/fslio.c b/fsliolib/fslio.c index 8f44a713..a8f7ba48 100644 --- a/fsliolib/fslio.c +++ b/fsliolib/fslio.c @@ -207,7 +207,7 @@ static int FslFileType(const char* fname) int flen; int retval=-1; if (fname==NULL) return retval; - flen = strlen(fname); + flen = (int)strlen(fname); /* debian@onerussian.com had to group conditions to avoid possible * illegal memory read-ins */ if (flen<5) return retval; /* smallest name + extension is a.nii */ @@ -301,7 +301,7 @@ char *FslMakeBaseName(const char *fname) char *basename; int blen; basename = nifti_makebasename(fname); - blen = strlen(basename); + blen = (int)strlen(basename); #ifdef HAVE_ZLIB if ((blen>7) && (strcmp(basename + blen-7,".mnc.gz") == 0)) { basename[blen-7]='\0'; return basename; } @@ -841,13 +841,13 @@ void* FslReadAllVolumes(FSLIO* fslio, char* filename) */ size_t FslReadVolumes(FSLIO *fslio, void *buffer, size_t nvols) { - int volbytes; + size_t volbytes; size_t retval=0; if (fslio==NULL) FSLIOERR("FslReadVolumes: Null pointer passed for FSLIO"); if (znz_isnull(fslio->fileptr)) FSLIOERR("FslReadVolumes: Null file pointer"); if (fslio->niftiptr!=NULL) { fslio->niftiptr->data = buffer; - volbytes = FslGetVolSize(fslio) * fslio->niftiptr->nbyper; + volbytes = FslGetVolSize(fslio) * (size_t)fslio->niftiptr->nbyper; retval = nifti_read_buffer(fslio->fileptr,fslio->niftiptr->data,nvols*volbytes,fslio->niftiptr); retval /= volbytes; } @@ -1168,13 +1168,14 @@ size_t FslReadTimeSeries(FSLIO *fslio, void *buffer, short xVox, short yVox, sho int FslSeekVolume(FSLIO *fslio, size_t vols) { - int offset; + znz_off_t offset; if (fslio==NULL) FSLIOERR("FslSeekVolume: Null pointer passed for FSLIO"); if (fslio->niftiptr!=NULL) { - offset = fslio->niftiptr->iname_offset + - vols * FslGetVolSize(fslio) * fslio->niftiptr->nbyper; + offset = (znz_off_t)fslio->niftiptr->iname_offset + + (znz_off_t)vols * (znz_off_t)FslGetVolSize(fslio) * fslio->niftiptr->nbyper; if (znz_isnull(fslio->fileptr)) FSLIOERR("FslSeekVolume: Null file pointer"); - return znzseek(fslio->fileptr,offset,SEEK_SET); + /* The int return cannot represent an offset beyond 2GB. */ + return (int)znzseek(fslio->fileptr,offset,SEEK_SET); } if (fslio->mincptr!=NULL) { fprintf(stderr,"Warning:: Minc is not yet supported\n"); @@ -1259,8 +1260,8 @@ void FslSetDimensionality(FSLIO *fslio, size_t dim) { if (fslio==NULL) FSLIOERR("FslSetDimensionality: Null pointer passed for FSLIO"); if (fslio->niftiptr!=NULL) { - fslio->niftiptr->ndim = dim; - fslio->niftiptr->dim[0] = dim; + fslio->niftiptr->ndim = (int)dim; + fslio->niftiptr->dim[0] = (int)dim; } if (fslio->mincptr!=NULL) { fprintf(stderr,"Warning:: Minc is not yet supported\n"); @@ -2046,7 +2047,7 @@ int FslReadRawHeader(void *buffer, const char* filename) fprintf(stderr,"Could not open header %s\n",filename); return 0; } - retval = znzread(buffer,1,348,fp); + retval = (int)znzread(buffer,1,348,fp); znzclose(fp); if (retval != 348) { fprintf(stderr,"Could not read header %s\n",filename); @@ -2150,9 +2151,9 @@ double ***FslGetVolumeAsScaledDouble(FSLIO *fslio, int vol) if ((fslio->niftiptr->dim[0] < 3) || (fslio->niftiptr->dim[0] > 4)) FSLIOERR("FslGetVolumeAsScaledDouble: Incorrect dataset dimension, 3D-4D needed"); - xx = (fslio->niftiptr->nx == 0 ? 1 : (long)fslio->niftiptr->nx); - yy = (fslio->niftiptr->ny == 0 ? 1 : (long)fslio->niftiptr->ny); - zz = (fslio->niftiptr->nz == 0 ? 1 : (long)fslio->niftiptr->nz); + xx = (fslio->niftiptr->nx == 0 ? 1 : fslio->niftiptr->nx); + yy = (fslio->niftiptr->ny == 0 ? 1 : fslio->niftiptr->ny); + zz = (fslio->niftiptr->nz == 0 ? 1 : fslio->niftiptr->nz); if (fslio->niftiptr->scl_slope == 0) { slope = 1.0; @@ -2234,10 +2235,10 @@ double ****FslGetBufferAsScaledDouble(FSLIO *fslio) if ((fslio->niftiptr->dim[0] <= 0) || (fslio->niftiptr->dim[0] > 4)) FSLIOERR("FslGetBufferAsScaledDouble: Incorrect dataset dimension, 1-4D needed"); - xx = (fslio->niftiptr->nx == 0 ? 1 : (long)fslio->niftiptr->nx); - yy = (fslio->niftiptr->ny == 0 ? 1 : (long)fslio->niftiptr->ny); - zz = (fslio->niftiptr->nz == 0 ? 1 : (long)fslio->niftiptr->nz); - tt = (fslio->niftiptr->nt == 0 ? 1 : (long)fslio->niftiptr->nt); + xx = (fslio->niftiptr->nx == 0 ? 1 : fslio->niftiptr->nx); + yy = (fslio->niftiptr->ny == 0 ? 1 : fslio->niftiptr->ny); + zz = (fslio->niftiptr->nz == 0 ? 1 : fslio->niftiptr->nz); + tt = (fslio->niftiptr->nt == 0 ? 1 : fslio->niftiptr->nt); if (fslio->niftiptr->scl_slope == 0) { slope = 1.0; diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index 0f519801..2997adf8 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -478,9 +478,9 @@ int nifti_fileexists(const char* fname); /* prototypes for internal functions - not part of exported library */ /* extension routines */ -static int nifti_read_extensions(nifti_image *nim, znzFile fp, int64_t remain); -static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, int remain, znzFile fp ); -static int nifti_check_extension(nifti_image *nim, int size,int code, int rem); +static int64_t nifti_read_extensions(nifti_image *nim, znzFile fp, int64_t remain); +static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, int64_t remain, znzFile fp ); +static int nifti_check_extension(nifti_image *nim, int size,int code, int64_t rem); static void update_nifti_image_for_brick_list(nifti_image * nim, int64_t nbricks); static int nifti_add_exten_to_list(nifti1_extension * new_ext, @@ -503,7 +503,7 @@ static int nifti_NBL_matches_nim(const nifti_image *nim, static int rci_read_data(nifti_image *nim, int64_t *pivots, int64_t *prods, int nprods, const int64_t dims[], char *data, znzFile fp, int64_t base_offset); -static int rci_alloc_mem(void **data, const int64_t prods[8], int nprods, int nbyper); +static int64_t rci_alloc_mem(void **data, const int64_t prods[8], int nprods, int nbyper); static int make_pivot_list(nifti_image * nim, const int64_t dims[8], int64_t pivots[8], int64_t prods[8], int * nprods ); @@ -886,7 +886,8 @@ int nifti_image_load_bricks( nifti_image * nim , int64_t nbricks, znzclose(fp); - return NBL->nbricks; + /* the count came from the caller, who passed it as this many bricks */ + return (int)NBL->nbricks; } @@ -5983,7 +5984,7 @@ nifti_image *nifti_image_read( const char *hname , int read_data ) return NULL; } else if ( rv == 1 ) { /* process special file type */ - nim = nifti_read_ascii_image( fp, hfile, filesize, read_data ); + nim = nifti_read_ascii_image( fp, hfile, (int)filesize, read_data ); znzclose(fp); free(hfile); return nim; @@ -6251,7 +6252,7 @@ nifti_image * nifti_read_ascii_image(znzFile fp, const char *fname, int flen, * * return the number of extensions read in, or < 0 on error *----------------------------------------------------------------------*/ -static int nifti_read_extensions( nifti_image *nim, znzFile fp, int64_t remain ) +static int64_t nifti_read_extensions( nifti_image *nim, znzFile fp, int64_t remain ) { nifti1_extender extdr; /* defines extension existence */ nifti1_extension extn; /* single extension to process */ @@ -6479,7 +6480,7 @@ static int nifti_fill_extension( nifti1_extension *ext, const char * data, * error : -1 *----------------------------------------------------------------------*/ static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, - int remain, znzFile fp ) + int64_t remain, znzFile fp ) { int swap = nim->byteorder != nifti_short_order(); int count, size, code = -1; @@ -6490,7 +6491,7 @@ static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, if( remain < 16 ){ if( g_opts.debug > 2 ) - fprintf(stderr,"-d only %d bytes remain, so no extension\n", remain); + fprintf(stderr,"-d only %" PRId64 " bytes remain, so no extension\n", remain); return 0; } @@ -6696,7 +6697,7 @@ int nifti_is_valid_ecode( int ecode ) /*---------------------------------------------------------------------- * check for valid size and code, as well as can be done *----------------------------------------------------------------------*/ -static int nifti_check_extension(nifti_image *nim, int size, int code, int rem) +static int nifti_check_extension(nifti_image *nim, int size, int code, int64_t rem) { /* check for bad code before bad size */ if( ! nifti_is_valid_ecode(code) ) { @@ -6713,7 +6714,7 @@ static int nifti_check_extension(nifti_image *nim, int size, int code, int rem) if( size > rem ){ if( g_opts.debug > 2 ) - fprintf(stderr,"-d ext size %d, space %d, no extension\n", size, rem); + fprintf(stderr,"-d ext size %d, space %" PRId64 ", no extension\n", size, rem); return 0; } @@ -9525,7 +9526,7 @@ static int rci_read_data(nifti_image * nim, int64_t * pivots, int64_t * prods, return total size on success, and < 0 on failure */ -static int rci_alloc_mem(void **data, const int64_t prods[8], int nprods, int nbyper ) +static int64_t rci_alloc_mem(void **data, const int64_t prods[8], int nprods, int nbyper ) { int64_t size; int memindex; diff --git a/nifti2/nifti_tool.c b/nifti2/nifti_tool.c index d92c5da8..a0300b2f 100644 --- a/nifti2/nifti_tool.c +++ b/nifti2/nifti_tool.c @@ -6781,7 +6781,7 @@ int act_disp_ci( nt_opts * opts ) } /* should we change disp_raw_data to allow for 64-bit nvalues? */ - disp_raw_data(data, nim->datatype, len64 / nim->nbyper, space, 1); + disp_raw_data(data, nim->datatype, (int)(len64 / nim->nbyper), space, 1); nifti_image_free(nim); } @@ -7585,7 +7585,7 @@ void * nt_read_header(const char * fname, int * nver, int * swapped, int check, * * the returned object is a (max 4-D) nifti_image *----------------------------------------------------------------------*/ -nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int len, +nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int64_t len, int64_t * list, nifti_brick_list * NBL) { nifti_image * nim; @@ -7631,8 +7631,8 @@ nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int len, disp_raw_data(opts->new_dim, DT_INT64, 8, ' ', 1); printf(" new_datatype = %d\n", opts->new_datatype); if( list && len > 0 ) { - printf(" brick_list[%d] = ", len); - disp_raw_data(list, DT_INT64, len, ' ', 1); + printf(" brick_list[%" PRId64 "] = ", len); + disp_raw_data(list, DT_INT64, (int)len, ' ', 1); } fflush(stdout); /* disp_raw_data uses stdout */ } diff --git a/nifti2/nifti_tool.h b/nifti2/nifti_tool.h index b93d115e..ef52167e 100644 --- a/nifti2/nifti_tool.h +++ b/nifti2/nifti_tool.h @@ -320,7 +320,7 @@ NI2_API int write_hdr2_to_file(nifti_2_header * nhdr, const char * fname); /* wrappers for nifti reading functions (allow MAKE_IM) */ NI2_API nifti_image * nt_image_read (nt_opts * opts, const char * fname, int read_data, int make_ver); -NI2_API nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int len, +NI2_API nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int64_t len, int64_t * list, nifti_brick_list * NBL); NI2_API void * nt_read_header(const char * fname, int * nver, int * swapped, int check, int new_datatype, int64_t new_dim[8]); diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index 1be70b11..21afd824 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -7096,7 +7096,9 @@ int nifti_read_collapsed_image( nifti_image * nim, const int dims [8], fprintf(stderr,"+d read %d bytes of collapsed image from %s\n", bytes, nim->fname); - return bytes; + /* nifti_read_subregion_image() is declared to return int; a subregion + larger than 2GB cannot be requested through its int region_size. */ + return (int)bytes; } @@ -7320,7 +7322,9 @@ int nifti_read_subregion_image( nifti_image * nim, } } znzclose(fp); - return bytes; + /* nifti_read_subregion_image() is declared to return int; a subregion + larger than 2GB cannot be requested through its int region_size. */ + return (int)bytes; }