MantisBT - ITK
View Issue Details
0006840ITKpublic2008-04-17 14:252010-10-21 12:31
Ryan Baumann 
Bradley Lowekamp 
normalcrashalways
closedfixed 
 
 
0006840: ImageFileReader::DoConvertBuffer/ConvertPixelBuffer segfaults if numberOfPixels > INT_MAX
Trying to do a file read which requires a buffer conversion with more than INT_MAX elements/pixels causes a segmentation fault (INT_MAX is defined as 2147483647 on most architectures). This is because all the functions in ConvertPixelBuffer take a size argument as a signed integer, so DoConvertBuffer performs a static_cast to int on the unsigned long numberOfPixels. An easy workaround is to remove the static casts and change all ConvertPixelBuffer functions to use an unsigned long for "size". It may, however, be preferable to instead use a type such as size_t.

Attached is a patch against 3.4.0, though the bug is still present in 3.6.0.
ImageReadWrite example, modified to PixelType float and Dimension = 3, reading a 2000 x 2000 x 537 NRRD of type short:

Debug: In /home/baumann/source/educe/Seg3D/thirdparty.bin/3.1.0/Linux/gcc-4.2.3-64bit/include/InsightToolkit/IO/itkImageFileReader.txx, line 311
ImageFileReader (0x7139f0): StreamableRegion set to =ImageRegion (0x713b00)
  Dimension: 3
  Index: [0, 0, 0]
  Size: [2000, 2000, 537]


Debug: In /home/baumann/source/educe/Seg3D/thirdparty.bin/3.1.0/Linux/gcc-4.2.3-64bit/include/InsightToolkit/Common/itkProcessObject.h, line 271
ImageFileReader (0x7139f0): returning ReleaseDataBeforeUpdateFlag of 0

Debug: In /home/baumann/source/educe/Seg3D/thirdparty.bin/3.1.0/Linux/gcc-4.2.3-64bit/include/InsightToolkit/IO/itkImageFileReader.txx, line 324
ImageFileReader (0x7139f0): ImageFileReader::GenerateData()
Allocating the buffer with the StreamableRegion
ImageRegion (0x713b00)
  Dimension: 3
  Index: [0, 0, 0]
  Size: [2000, 2000, 537]



Debug: In /home/baumann/source/educe/Seg3D/thirdparty.bin/3.1.0/Linux/gcc-4.2.3-64bit/include/InsightToolkit/IO/itkImageFileReader.txx, line 354
ImageFileReader (0x7139f0): ioRegion: ImageIORegion (0x7fff30d31db0)
  Dimension: 3
  Index: 0 0 0
  Size: 2000 2000 537


Debug: In /home/baumann/source/educe/Seg3D/thirdparty.bin/3.1.0/Linux/gcc-4.2.3-64bit/include/InsightToolkit/IO/itkImageFileReader.txx, line 370
ImageFileReader (0x7139f0): Buffer conversion required.

Debug: In /home/baumann/source/educe/Seg3D/thirdparty.bin/3.1.0/Linux/gcc-4.2.3-64bit/include/InsightToolkit/IO/itkImageFileReader.txx, line 381
ImageFileReader (0x7139f0): Buffer conversion required from: s to: f

Segmentation fault (core dumped)
No tags attached.
patch itkbug.patch (11,047) 2008-04-17 14:25
https://public.kitware.com/Bug/file/1414/itkbug.patch
Issue History
2008-04-17 14:25Ryan BaumannNew Issue
2008-04-17 14:25Ryan BaumannFile Added: itkbug.patch
2009-02-03 14:03Bradley LowekampStatusnew => assigned
2009-02-03 14:03Bradley LowekampAssigned To => Bradley Lowekamp
2009-08-13 09:28Bradley LowekampNote Added: 0017115
2009-08-13 09:28Bradley LowekampNote Added: 0017116
2009-08-13 09:28Bradley LowekampStatusassigned => resolved
2009-08-13 09:28Bradley LowekampResolutionopen => fixed
2010-10-21 12:31Gabe HartStatusresolved => closed

Notes
(0017115)
Bradley Lowekamp   
2009-08-13 09:28   
Committed fix:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/IO/itkConvertPixelBuffer.h.diff?cvsroot=Insight&r1=1.11&r2=1.12 [^]
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/IO/itkConvertPixelBuffer.txx.diff?cvsroot=Insight&r1=1.25&r2=1.26 [^]
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/IO/itkImageFileReader.h.diff?cvsroot=Insight&r1=1.32&r2=1.33 [^]
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/IO/itkImageFileReader.txx.diff?cvsroot=Insight&r1=1.87&r2=1.88 [^]

added test:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Testing/Code/IO/itkLargeImageWriteConvertReadTest.cxx?cvsroot=Insight&rev=1.1&view=markup [^]
(0017116)
Bradley Lowekamp   
2009-08-13 09:28   
The committed code seems to have resolved the problem.