Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cifti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ if(NIFTI_BUILD_TESTING AND NIFTI_BUILD_APPLICATIONS)
set_tests_properties( ${TEST_PREFIX}_mim_summary_known_child
PROPERTIES PASS_REGULAR_EXPRESSION "BrainModel" )

# The CIFTI extension is found even when another extension precedes it.
add_test( NAME ${TEST_PREFIX}_tool_cext_not_first
COMMAND $<TARGET_FILE:${NIFTI_PACKAGE_PREFIX}cifti_tool>
-input ${CMAKE_CURRENT_LIST_DIR}/testdata/cext_second_extension.nii
-disp_cext )
set_tests_properties( ${TEST_PREFIX}_tool_cext_not_first
PROPERTIES PASS_REGULAR_EXPRESSION "<MapName>demo</MapName>"
FAIL_REGULAR_EXPRESSION "no CIFTI extension" )

# An extension payload that fills esize-8 with no NUL must not be read
# past its end; the regex pins that the payload is still parsed.
add_test( NAME ${TEST_PREFIX}_tool_unterminated_cext
Expand Down
15 changes: 9 additions & 6 deletions cifti/cifti_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,22 @@ int disp_cifti_extension(nifti_image * nim, opts_t * opts)
opts->fout ? opts->fout : "DEFAULT" );

if( !nim ) return 1;
ext = nim->ext_list;
/* find the CIFTI extension, if any; it need not be first in the list */
ext = NULL;
for( ind = 0; ind < nim->num_ext; ind++ )
if( ext->ecode == NIFTI_ECODE_CIFTI ) break;
if( nim->ext_list[ind].ecode == NIFTI_ECODE_CIFTI ) {
ext = nim->ext_list + ind;
break;
}

fp = open_write_stream(opts->fout);
if( ext && ext->ecode != NIFTI_ECODE_CIFTI ) {
if( !ext ) {
fprintf(fp, "** no CIFTI extension in %s\n",nim->fname?nim->fname:"NULL");
close_stream(fp);
return 1;
}

if(ext) {
fprintf(fp, "%.*s\n", ext->esize-8, ext->edata);
}
fprintf(fp, "%.*s\n", ext->esize-8, ext->edata);

/* possibly close file */
close_stream(fp);
Expand Down
Binary file added cifti/testdata/cext_second_extension.nii
Binary file not shown.
Loading