Status: New
Owner: ----
Labels: Type-Defect Priority-Medium Milestone-Release1.4
New issue 63 by
jdswinb...@gmail.com: Segfault on conversion to FITS.
http://code.google.com/p/casacore/issues/detail?id=63
(Apologies in advance for the slightly rambling nature of what follows...)
Given the following code:
#include <images/Images/ImageProxy.h>
#include <casa/BasicSL/String.h>
#include <casa/Arrays/Vector.h>
int main(void) {
casa::Vector<casa::String> names(1, casa::String("input.fits"));
casa::ImageProxy ipx(names, 0);
ipx.toFits(casa::String("output.fits"));
return 0;
}
And for an appropriately constructed input.fits, I get a segfault.
In particular, the error arises from FITSHistoryUtil::toHISTORY(). This
function is designed to process "a group of contiguous records in the same
format" (line 294 of FITSHistoryUtil.cc). There are two possible
formats: "AIPS++ format", in which one history entry consists of two lines,
and standard format, in which a history entry is one line.
The function iterates over all records with an index greater than some
given starting point (argument firstLine). The format of the first record
is taken as the format of the block. If a subsequent record does not have a
matching format, it fails the test at line 301 and is skipped.
This works fine, assuming that the format changes only once. However, if
the format changes multiple times, we are in trouble. Consider a log that
looks like:
(format 1)
(format 1)
(format 2)
(format 1)
Here, the third line is in a different format, and will be skipped.
However, we keep iterating, and attempt to add the fourth line to the
history Vector. Unfortunately, we attempt to add it at the wrong position
in the Vector: the index it will be added at is calculated by according to
the total number of lines seen, not according to the number of lines which
have actually been added. Thus, at line 323 of FITSHistoryUtil.cc:
history(2*(line - firstLine) + 0) = tmp1;
The Vector history is sized to only take three entries (in this example),
but we attempt to add something in fourth position. A segfault results.
The following simple fix avoids the segfault:
--- a/fits/FITS/FITSHistoryUtil.cc
+++ b/fits/FITS/FITSHistoryUtil.cc
@@ -324,6 +324,9 @@ uInt FITSHistoryUtil::toHISTORY(Vector<String>&
history, Bool& aipsppFormat,
} else {
history(line - firstLine) = message;
}
+ } else {
+ // Records not in same format: end this block.
+ break;
}
}
}
This also causes the function to behave as per the comments, since it now
really does process contiguous blocks in the same format.
This slightly modifies the output, as each contiguous block is now
bracketed by CASA START/END LOGTABLE in the output FITS file. I'm not clear
if that's of fundamental importance; at any rate, I reckon it's preferable
to a segfault.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings