External Email - Use Caution        

While I do no know and have not looked at the source code in question, if you lookup that error online, one explanation is memory corruption is happening by writing beyond the end of allocated memory, e.g., by using free(g) incorrectly.

However the code is written, an issue with memory allocation might be exacerbated depending upon how memory management is done on the platform.  Memory management on MacOS is extremely aggressive about swapping out to disk well before physical RAM is in danger of being underrun.   Or it is virtually impossible to run out of physical RAM on macOS though things may slow down to a crawl and/or thrash.   It might be informative to know if you are hitting memory limits in the cluster and in the container (where it crashes) - but for some reason not on MacOS.  Similarly, it would be interesting to know if the memory error occurs when run on a stand alone linux workstation.

- R.

On May 17, 2023, at 16:27, Douglas N. Greve <dgreve@mgh.harvard.edu> wrote:

        External Email - Use Caution        

So the same input volume will sometimes succeed and sometimes fail depending upon the platform? 

On 5/17/2023 12:05 PM, Patrick Sadil wrote:
        External Email - Use Caution        
Hello,
     I am trying to process several images with MiDeFace but running into issues with memory and uncaught exceptions.

Of 50 images, about half are processed successfully. On the other half MiDeFace fails consistently. However, whether the images fail seems to depend on the platform. Here's what I've tried
  • Fails
    • freesurfer-linux-centos7_x86_64-7.4.0.tar.gz install on HPC, CentOS Linux release 7.9.2009 (Core)
    • freesurfer-linux-centos7_x86_64-7.3.2.tar.gz install on HPC, CentOS Linux release 7.9.2009 (Core)
    • Apptainer image from docker://freesurfer/freesurfer:7.3.2, (this is built on CentOS:7) run on HPC
    • Docker image from docker://freesurfer/freesurfer:7.3.2, (this is built on CentOS:7) Apple M1 Pro; 13.3.1
    • Custom docker image (below), built and run on Apple M1 Pro; 13.3.1
  • Succeeds
    • freesurfer-darwin-macOS-7.4.0.pkg, installed and run on Apple M1 Pro; 13.3.1

So, I'm not sure whether this is a bug or something that I need to configure differently.

############

Example apptainer command

$ apptainer exec -e -B $(pwd):/data docker://freesurfer/freesurfer:7.3.2 mideface --i /data/volume.nii.gz --o /data/defaced.nii.gz --odir /data/qa

Example docker command

> docker run --rm -it -v $(pwd):/data freesurfer/freesurfer:7.3.2 mideface --i /data/volume.nii.gz --o /data/defaced.nii.gz --odir /data/qa


Example "bare" command

> mideface --i volume.nii.gz --o defaced.nii.gz --odir qa

############

On the CentOS runs, the error is

MiDeface::SegFace()
*** Error in `mri_defacer': double free or corruption (!prev): 0x000000000e4d64f0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x81329)[0x4001f6b329]
mri_defacer[0x4b0ebe]
mri_defacer[0x422c15]
mri_defacer[0x415308]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x4001f0c555]
mri_defacer[0x418367]
======= Memory map: ========
400000-700000 r-xp 00000000 fe:01 4223092                                /usr/local/freesurfer/bin/mri_defacer
700000-900000 ---p 00000000 00:00 0                                      
900000-908000 r--p 00300000 fe:01 4223092                                /usr/local/freesurfer/bin/mri_defacer
908000-932000 rw-p 00308000 fe:01 4223092                                /usr/local/freesurfer/bin/mri_defacer
932000-13ee1000 rw-p 00000000 00:00 0                                    
4000000000-4000001000 ---p 00000000 00:00 0                              
4000001000-4000801000 rw-p 00000000 00:00 0                              [stack]
4000801000-4000823000 r-xp 00000000 fe:01 2527596                        /usr/lib64/ld-2.17.so
4000823000-4000a22000 ---p 00000000 00:00 0                              
4000a22000-4000a23000 r--p 00021000 fe:01 2527596                        /usr/lib64/ld-2.17.so
4000a23000-4000a24000 rw-p 00022000 fe:01 2527596                        /usr/lib64/ld-2.17.so
4000a24000-4000a27000 rw-p 00000000 00:00 0                              
4000a2b000-4000a2c000 rw-p 00000000 00:00 0                              
4000a2c000-4000a41000 r-xp 00000000 fe:01 2527648                        /usr/lib64/libz.so.1.2.7
4000a41000-4000c40000 ---p 00015000 fe:01 2527648                        /usr/lib64/libz.so.1.2.7
4000c40000-4000c41000 r--p 00014000 fe:01 2527648                        /usr/lib64/libz.so.1..2.7
4000c41000-4000c42000 rw-p 00015000 fe:01 2527648                        /usr/lib64/libz.so.1.2.7
4000c42000-4000c59000 r-xp 00000000 fe:01 2527629                        /usr/lib64/libpthread-2.17.so
4000c59000-4000e58000 ---p 00017000 fe:01 2527629                        /usr/lib64/libpthread-2.17.so
4000e58000-4000e59000 r--p 00016000 fe:01 2527629                        /usr/lib64/libpthread-2.17.so
4000e59000-4000e5a000 rw-p 00017000 fe:01 2527629                        /usr/lib64/libpthread-2.17.so
4000e5a000-4000e5e000 rw-p 00000000 00:00 0                              
4000e5e000-4000e60000 r-xp 00000000 fe:01 2527609                        /usr/lib64/libdl-2.17.so
4000e60000-4001060000 ---p 00002000 fe:01 2527609                        /usr/lib64/libdl-2..17.so
4001060000-4001061000 r--p 00002000 fe:01 2527609                        /usr/lib64/libdl-2.17.so
4001061000-4001062000 rw-p 00003000 fe:01 2527609                        /usr/lib64/libdl-2.17.so
4001062000-4001063000 rw-p 00000000 00:00 0                              
4001063000-4001164000 r-xp 00000000 fe:01 2527611                        /usr/lib64/libm-2.17.so
4001164000-4001363000 ---p 00101000 fe:01 2527611                        /usr/lib64/libm-2.17.so
4001363000-4001364000 r--p 00100000 fe:01 2527611                        /usr/lib64/libm-2..17.so
4001364000-4001365000 rw-p 00101000 fe:01 2527611                        /usr/lib64/libm-2.17.so
4001365000-400138a000 r-xp 00000000 fe:01 2527938                        /usr/lib64/libgomp.so.1.0.0
400138a000-4001589000 ---p 00025000 fe:01 2527938                        /usr/lib64/libgomp.so.1.0.0
4001589000-400158a000 r--p 00024000 fe:01 2527938                        /usr/lib64/libgomp.so.1.0.0
400158a000-400158b000 rw-p 00025000 fe:01 2527938                        /usr/lib64/libgomp.so.1.0..0
400158b000-4001593000 r-xp 00000000 fe:01 2527607                        /usr/lib64/libcrypt-2.17.so
4001593000-4001792000 ---p 00008000 fe:01 2527607                        /usr/lib64/libcrypt-2.17.so
4001792000-4001793000 r--p 00007000 fe:01 2527607                        /usr/lib64/libcrypt-2.17.so
4001793000-4001794000 rw-p 00008000 fe:01 2527607                        /usr/lib64/libcrypt-2.17.so
4001794000-40017c3000 rw-p 00000000 00:00 0                              
40017c3000-40017ca000 r-xp 00000000 fe:01 2527633                        /usr/lib64/librt-2.17.so
40017ca000-40019c9000 ---p 00007000 fe:01 2527633                        /usr/lib64/librt-2.17.so
40019c9000-40019ca000 r--p 00006000 fe:01 2527633                        /usr/lib64/librt-2.17.so
40019ca000-40019cb000 rw-p 00007000 fe:01 2527633                        /usr/lib64/librt-2.17.so
40019cb000-4001ab4000 r-xp 00000000 fe:01 2123191                        /usr/lib64/libstdc++.so.6.0.19
4001ab4000-4001cb4000 ---p 000e9000 fe:01 2123191                        /usr/lib64/libstdc++.so.6.0.19
4001cb4000-4001cbc000 r--p 000e9000 fe:01 2123191                        /usr/lib64/libstdc++.so.6.0.19
4001cbc000-4001cbe000 rw-p 000f1000 fe:01 2123191                        /usr/lib64/libstdc++.so.6..0.19
4001cbe000-4001cd3000 rw-p 00000000 00:00 0                              
4001cd3000-4001ce8000 r-xp 00000000 fe:01 2123006                        /usr/lib64/libgcc_s-4.8.5-20150702.so.1
4001ce8000-4001ee7000 ---p 00015000 fe:01 2123006                        /usr/lib64/libgcc_s-4.8.5-20150702.so.1
4001ee7000-4001ee8000 r--p 00014000 fe:01 2123006                        /usr/lib64/libgcc_s-4.8.5-20150702.so.1
4001ee8000-4001ee9000 rw-p 00015000 fe:01 2123006                        /usr/lib64/libgcc_s-4.8.5-20150702.so.1
4001ee9000-4001eea000 rw-p 00000000 00:00 0                              
4001eea000-40020ae000 r-xp 00000000 fe:01 2527603                        /usr/lib64/libc-2.17.so
40020ae000-40022ad000 ---p 001c4000 fe:01 2527603                        /usr/lib64/libc-2.17.so
40022ad000-40022b1000 r--p 001c3000 fe:01 2527603                        /usr/lib64/libc-2.17.so
40022b1000-40022b3000 rw-p 001c7000 fe:01 2527603                        /usr/lib64/libc-2.17.so
40022b3000-40022b8000 rw-p 00000000 00:00 0                              
40022b8000-40022ba000 r-xp 00000000 fe:01 2527589                        /usr/lib64/libfreebl3.so
40022ba000-40024b9000 ---p 00002000 fe:01 2527589                        /usr/lib64/libfreebl3.so
40024b9000-40024ba000 r--p 00001000 fe:01 2527589                        /usr/lib64/libfreebl3.so
40024ba000-40024bb000 rw-p 00002000 fe:01 2527589                        /usr/lib64/libfreebl3.so
40024bb000-40024c0000 rw-p 00000000 00:00 0                              
40024c1000-40024c2000 rw-p 00000000 00:00 0                              
40024c7000-40024d3000 r-xp 00000000 fe:01 2527621                        /usr/lib64/libnss_files-2.17.so
40024d3000-40026d2000 ---p 0000c000 fe:01 2527621                        /usr/lib64/libnss_files-2.17.so
40026d2000-40026d3000 r--p 0000b000 fe:01 2527621                        /usr/lib64/libnss_files-2.17.so
40026d3000-40026d4000 rw-p 0000c000 fe:01 2527621                        /usr/lib64/libnss_files-2.17.so
40026d4000-40026da000 rw-p 00000000 00:00 0                              
40026dc000-4004767000 rw-p 00000000 00:00 0                              
400476a000-400c2f1000 rw-p 00000000 00:00 0                              
400db9d000-400e3c0000 rw-p 00000000 00:00 0                              
400e3c1000-401044c000 rw-p 00000000 00:00 0                              
401044d000-40215ba000 rw-p 00000000 00:00 0                              
40215bd000-4023648000 rw-p 00000000 00:00 0                              
4023649000-4023ec1000 rw-p 00000000 00:00 0                              
4023eca000-4023ecb000 rw-p 00000000 00:00 0                              
4024000000-4024021000 rw-p 00000000 00:00 0                              
4024021000-4028000000 ---p 00000000 00:00 0                              
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0                  [vsyscall]
===============================================

MiDeface::FaceIntensityStats()
Mode2 12 12  4362
qemu: uncaught target signal 6 (Aborted) - core dumped
Abort
ERROR:

############

With a docker image using Ubuntu base, the error is 

MiDeface::SegFace()
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault
ERROR:


############
# Dockerfile

FROM ubuntu:22.04

COPY freesurfer_ubuntu22-7.4.0_amd64.deb /tmp/fs.deb

# install
RUN apt-get update \
    && apt-get install -y /tmp/fs.deb \
    && rm -rf /var/lib/apt/lists/* \
    && rm /tmp/fs.deb

COPY license /usr/local/freesurfer/7.4.0/.license

# setup fs env
ENV OS Linux
ENV FREESURFER_HOME /usr/local/freesurfer/7.4.0
ENV PATH ${FREESURFER_HOME}/bin:${FREESURFER_HOME}/fsfast/bin:${FREESURFER_HOME}/tktools:{$FREESURFER_HOME}/mni/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV FREESURFER ${FREESURFER_HOME}
ENV SUBJECTS_DIR ${FREESURFER_HOME}/subjects
ENV LOCAL_DIR ${FREESURFER_HOME}/local
ENV FSFAST_HOME ${FREESURFER_HOME}/fsfast
ENV FMRI_ANALYSIS_DIR ${FREESURFER_HOME}/fsfast
ENV FUNCTIONALS_DIR ${FREESURFER_HOME}/sessions
ENV FS_LICENSE ${FREESURFER_HOME}/.license

# set default fs options
ENV FS_OVERRIDE 0
ENV FIX_VERTEX_AREA ""
ENV FSF_OUTPUT_FORMAT nii.gz

# mni env requirements
ENV MINC_BIN_DIR ${FREESURFER_HOME}/mni/bin
ENV MINC_LIB_DIR ${FREESURFER_HOME}/mni/lib
ENV MNI_DIR ${FREESURFER_HOME}/mni
ENV MNI_DATAPATH ${FREESURFER_HOME}/mni/data
ENV MNI_PERL5LIB ${FREESURFER_HOME}/mni/share/perl5
ENV PERL5LIB ${FREESURFER_HOME}/mni/share/perl5


Thanks!
Patrick Sadil, PhD (he/him/his)
Research Associate

_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
MailScanner has detected a possible fraud attempt from "secure-web.cisco.com" claiming to be https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer

_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
MailScanner has detected a possible fraud attempt from "secure-web.cisco.com" claiming to be https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer