MantisBT - ITK
View Issue Details
0008371ITKpublic2009-01-13 11:572010-10-21 14:13
Bradley Lowekamp 
Bradley Lowekamp 
normalminoralways
assignedopen 
 
 
0008371: large MetaImage files and 32-bit produces erroneous results
When using streaming and 4GB+ file and a 32-bit build only the first 4 GB are read. Requested regions beyond that appear to be read mod 32-bit, that is they go back to the beginning of the file. This should be able to be reproduced with the itkImageFileWriterStreamingTest1 with a 4GB+ file.
No tags attached.
related to 0009260assigned Luis Ibanez Integer types inconsistency in 64 bits platforms 
Issue History
2009-01-13 11:57Bradley LowekampNew Issue
2009-01-13 12:00Bradley LowekampNote Added: 0014547
2009-01-14 14:41Bradley LowekampNote Added: 0014554
2009-01-14 17:24Bradley LowekampNote Added: 0014555
2009-01-14 17:25Bradley LowekampNote Edited: 0014547
2009-01-14 17:26Bradley LowekampNote Edited: 0014547
2009-01-14 17:29Bradley LowekampNote Edited: 0014555
2009-01-15 04:50Mathieu MalaterreNote Added: 0014571
2009-02-03 13:50Bradley LowekampStatusnew => assigned
2009-02-03 13:50Bradley LowekampAssigned To => Bradley Lowekamp
2009-11-22 10:00Bradley LowekampAssigned ToBradley Lowekamp => Julien Jomier
2009-11-22 10:01Bradley LowekampRelationship addedrelated to 0009260
2010-10-21 14:13Hans JohnsonAssigned ToJulien Jomier => Bradley Lowekamp

Notes
(0014547)
Bradley Lowekamp   
2009-01-13 12:00   
(edited on: 2009-01-14 17:26)
Searching for problematic code, (ie incorrect usage of size_t) I made the following changes which may fix this bug:

Index: metaImage.cxx
===================================================================
RCS file: /cvsroot/Insight/Insight/Utilities/MetaIO/metaImage.cxx,v
retrieving revision 1.107
diff -r1.107 metaImage.cxx
1901c1901
< size_t endfile = tmpWriteStream->tellp();
---
> unsigned long endfile = tmpWriteStream->tellp();
1904c1904
< size_t padding = seekpos-endfile;
---
> unsigned long padding = seekpos-endfile;
2129c2129
< size_t padding = seekpos-currentPos;
---
> unsigned long padding = seekpos-currentPos;

*not the fix, but wrong types are still used*

(0014554)
Bradley Lowekamp   
2009-01-14 14:41   
I have been able to reproduce this on apple and linux systems
(0014555)
Bradley Lowekamp   
2009-01-14 17:24   
(edited on: 2009-01-14 17:29)
I have been able to track the problem down to the following on 32-bit systems:

sizeof(std::streamsize):4
sizeof(std::pos_type):16
sizeof(unsigned long):4

metaImage utilizes unsigned long for seeking and teling around files. This is now clearly the wrong type and the corrected type should be related to pos_type. Also calculations which are assigned to this type need to be casts to avoid overflow.

A quick local correction verified that this was the problem and this is the fix.

(0014571)
Mathieu Malaterre   
2009-01-15 04:50   
No, tellp() returns a streampos (castable to int):

http://www.cplusplus.com/reference/iostream/ostream/tellp.html [^]

Do not forget to provide a patch bor bcc compiler (yeah ITK supports old/broken compiler).

http://www.cmake.org/Wiki/CMake_Borland_Compiler_Issues [^]