From 25800749dfe52d49c2f2c6716bbc0665331c4fae Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Sat, 14 Nov 2026 12:54:48 -0500 Subject: [PATCH 1/3] Remove AI generated code committed in my name that I did not write Git blame shows this as something I wrote, but I did not. --- nifti2/nifti_tool.c | 10 ---------- niftilib/nifti1_tool.c | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/nifti2/nifti_tool.c b/nifti2/nifti_tool.c index 3357a373..a79153da 100644 --- a/nifti2/nifti_tool.c +++ b/nifti2/nifti_tool.c @@ -3860,16 +3860,6 @@ int modify_field(void * basep, size_t baselen, field_s * field, const char * dat 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.c b/niftilib/nifti1_tool.c index a6fb0b3a..f8e4d376 100644 --- a/niftilib/nifti1_tool.c +++ b/niftilib/nifti1_tool.c @@ -2922,16 +2922,6 @@ int modify_field(void * basep, size_t baselen, field_s * field, const char * dat 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: From e3dff7cf344cc4294dad414332a3e772d27314ce Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Sat, 14 Nov 2026 12:44:07 -0500 Subject: [PATCH 2/3] Match parameter names in source and header files This discrepancy was pointed out by a bot, but the PR was merged before it could be acted upon. --- nifti2/nifti_tool.h | 4 ++-- niftilib/nifti1_tool.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nifti2/nifti_tool.h b/nifti2/nifti_tool.h index f72579f6..f6f5c6fb 100644 --- a/nifti2/nifti_tool.h +++ b/nifti2/nifti_tool.h @@ -310,8 +310,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, 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 modify_all_fields(void *basep, size_t baselen, nt_opts *opts, field_s *fields, int flen); +NI2_API int modify_field (void * basep, size_t baselen, 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.h b/niftilib/nifti1_tool.h index 50bbce5d..39e48dfe 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, 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 modify_all_fields(void *basep, size_t baselen, nt_opts *opts, field_s *fields, int flen); +int modify_field (void * basep, size_t baselen, 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 668937204678ca797ccf501754fe29c2521d9073 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 2 Jan 2026 00:16:49 -0500 Subject: [PATCH 3/3] Make use of newly added buffer parameter in an assert for now The newly added buffer length parameters are for eventual -fbounds-safety compatibility. This first step just changed the function signatures without changing any real behaviour, as such the length is only used in an assert for now. --- nifti2/nifti_tool.c | 2 ++ niftilib/nifti1_tool.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/nifti2/nifti_tool.c b/nifti2/nifti_tool.c index a79153da..8d1935ee 100644 --- a/nifti2/nifti_tool.c +++ b/nifti2/nifti_tool.c @@ -208,6 +208,7 @@ static const char g_version[] = "2.13"; static const char g_version_date[] = "February 27, 2022"; static int g_debug = 1; +#include #include #include #include @@ -4011,6 +4012,7 @@ int modify_field(void * basep, size_t baselen, field_s * field, const char * dat case NT_DT_STRING: { + assert(field->offset + field->len <= baselen); (void)baselen; char * dest = (char *)basep + field->offset; nchars = dataLength; strncpy(dest, data, field->len); diff --git a/niftilib/nifti1_tool.c b/niftilib/nifti1_tool.c index f8e4d376..862867fb 100644 --- a/niftilib/nifti1_tool.c +++ b/niftilib/nifti1_tool.c @@ -162,6 +162,7 @@ static const char * g_history[] = static const char g_version[] = "version 1.24 (September 26, 2012)"; static int g_debug = 1; +#include #include #include #include @@ -3032,6 +3033,7 @@ int modify_field(void * basep, size_t baselen, field_s * field, const char * dat case NT_DT_STRING: { + assert(field->offset + field->len <= baselen); (void)baselen; char * dest = (char *)basep + field->offset; nchars = dataLength; strncpy(dest, data, field->len);