Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very large images cause std::bad_array_new_length in Sift due to overflow of INT type #237

Open
Oblomov opened this issue Jan 8, 2024 · 0 comments

Comments

@Oblomov
Copy link

Oblomov commented Jan 8, 2024

Trying to process 3 images with these characteristics

img1.tif TIFF64 39164x57303 39164x57303+0+0 16-bit Grayscale Gray 4.18103GiB 0.000u 0:00.000
img2.tif TIFF64 39378x57512 39378x57512+0+0 16-bit Grayscale Gray 4.21921GiB 0.000u 0:00.000
img3.tif TIFF64 39611x59355 39611x59355+0+0 16-bit Grayscale Gray 4.38017GiB 0.000u 0:00.000

causes Sift to throw an std::bad_array_new_length error. Compiling the current master with debug info shows that the issue is the use of the INT type (that maps to int) for file and/or memory sizes, which with these images results in an overflow :

Starting program: /home/user/src/micmac/bin/mm3d Sift ./img1.tif -o ./Pastis/LBPpimg1.tif.dat
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
terminate called after throwing an instance of 'std::bad_array_new_length'
  what():  std::bad_array_new_length

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff6643859 in __GI_abort () at abort.c:79
#2  0x00007ffff6a1b8d1 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff6a2737c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff6a273e7 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff6a27699 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff6a1b3a6 in __cxa_throw_bad_array_new_length () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x0000555556375d9d in DataGenImType<unsigned short, int>::Initializer (this=this@entry=0x555558943d70, sz_tot=sz_tot@entry=-2050752604, to_init=to_init@entry=false, v_init=v_init@entry=0, str_init=str_init@entry=0x0) at /home/user/src/micmac/src/bitm/im2d_tpl.cpp:356
#8  0x0000555556375de2 in DataGenImType<unsigned short, int>::DataGenImType (this=this@entry=0x555558943d70, sz_tot=-2050752604, to_init=<optimized out>, v_init=0, str_init=0x0) at /home/user/src/micmac/include/private/bitm_def.h:56
#9  0x00005555563763d3 in DataIm2D<unsigned short, int>::DataIm2D (this=0x555558943d70, Tx=39164, Ty=57303, to_init=<optimized out>, v_init=<optimized out>, str_init=<optimized out>, DataLin=0x0, Data=0x0, tx_phys=-1, NoDataLin=false) at /home/user/src/micmac/src/bitm/im2d_tpl.cpp:545
#10 0x00005555563765c3 in Im2D<unsigned short, int>::Im2D (this=0x7fffffffd0e0, tx=39164, ty=57303) at /home/user/src/micmac/src/bitm/im2d_tpl.cpp:1154
#11 0x00005555563644ad in D2alloc_im2d (type_el=<optimized out>, tx=tx@entry=39164, ty=ty@entry=57303) at /home/user/src/micmac/src/bitm/im2d_tpl.cpp:2364
#12 0x0000555557759b95 in Tiff_Im::ReadIm (this=this@entry=0x7fffffffd190) at /home/user/src/micmac/src/tiff/tiff_header.cpp:2087
#13 0x0000555557d08666 in RealImage1::load (this=this@entry=0x7fffffffd350, i_filename="./img1.tif") at /home/user/src/micmac/src/uti_image/Sift/RealImage1.cpp:478
#14 0x00005555566a7a1c in Sift_main (argc=<optimized out>, argv=<optimized out>) at /home/user/src/micmac/src/uti_image/CPP_Sift.cpp:362
#15 0x00005555561b80e3 in GenMain (argc=5, argv=0x7fffffffdca8, aVComs=...) at /home/user/src/micmac/src/CBinaires/mm3d.cpp:1652
#16 0x0000555555ec6bd3 in main (argc=5, argv=0x7fffffffdca8) at /home/user/src/micmac/src/CBinaires/mm3d.cpp:1752

Supporting these images probably requires the use of 64-bit integers for these memory-related data types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant