neurolabusc / surf-ice

GLSL surface rendering source code. Compiled versions available from NITRC. Loads 3DS, CTM, DXF, FreeSurfer, GII (GIfTI), GTS, LWO2, MS3D, MZ3, NV (BrainNetViewer), OBJ, OFF, PLY, STL, VTK. Tractography formats include BFloat, PDB, TCK, TRK, and VTK. Also NIfTI format voxelwise images.
https://www.nitrc.org/plugins/mwiki/index.php/surfice:MainPage
BSD 2-Clause "Simplified" License
101 stars 23 forks source link

SurfIce cannot handle filepaths longer than 255 characters #35

Closed ToeKneeFan closed 2 years ago

ToeKneeFan commented 2 years ago

This is perhaps less a bug and more an archaic path-length limitation (except maybe in Windows OS, where there is a similar value for the default MAX_PATH limitation). Using SurfIce 6-Oct-2021 on both macOS Monterey 12.5 21G72 and Ubuntu 22.04.1 LTS, I have found that SurfIce will raise an error if the length of a filepath is longer than 255 characters.

As a minimum reproducible example, I artificially renamed the built-in file "motor_4t95vol.nii.gz" to "/home/blank/Downloads/folder_1/folder_2/folder_3/folder_4/folder_5/folder_6/folder_7/folder_8/folder_9/folder_10/folder_11/folder_12/folder_13/folder_14/folder_15/folder_16/folder_17/folder_18/folder_19/folder_20/motor_4t95vol___.nii.gz" (255 characters), which loaded fine as an overlay in SurfIce. Adding an extra underscore brought the filepath to 256 characters, which fails with the following error message:

Could not open gzip compressed file /home/blank/Downloads/folder_1/folder_2/folder_3/folder_4/folder_5/folder_6/folder_7/folder_8/folder_9/folder_10/folder_11/folder_12/folder_13/folder_14/folder_15/folder_16/folder_17/folder_18/folder_19/folder_20/motor_4t95vol_______________________.nii.gz.

Press OK to ignore and risk data corruption.
Press Abort to kill the program.

In neuroimaging data sets, files are sometimes deeply nested, for data provenance (e.g., per the BIDS specification), which can sometimes bring filepaths to longer than 255 characters. With SurfIce, this unexpectedly produces an error due to the path limitation. This can be circumvented by renaming or symbolic linking, but in case this is not intended behavior, I thought I would raise an issue.

neurolabusc commented 2 years ago

This is specific to macOS. Can you please try updated release to see if this fixes your issue. Be aware that macOS GUI applications are unable to read files outside their 'sandbox', regardless of file read/write permissions.

ToeKneeFan commented 2 years ago

Thank you very much for the quick response! I tested with the updated release, and the issue continues to persist; overlays with filepaths up to 255 load fine, those with filepaths longer than 255 fail to read with the same error.

I tested (not this updated release but the standard v1.0.20211006) in Ubuntu 22.04.1 LTS and observed the same issue.

In hindsight, it is perhaps not an issue with Surfice itself but a Pascal library or base function called by the program and thus may be unavoidable.

neurolabusc commented 2 years ago

Did you test the latest download on macOS or only Linux?

neurolabusc commented 2 years ago

It is a documented limitation Note that the filename (including path) can be only 255 characters long. This situation is unlikely to change. While there are work arounds, there are situations where the block read is faster than file streams.

ToeKneeFan commented 2 years ago

Thank you very much for your investigation into this! That makes sense, particularly given the generation of the language. For my purposes, I have been able to work around it by using a tempfile symbolic link (with a short path) as an intermediate.