<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta4" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45290 - Support odd files where the POIFS header block comes after the data blocks, and is on the data blocks list</header>
<action dev="POI-DEVELOPERS" type="fix">46184 - More odd escaped date formats</action>
<action dev="POI-DEVELOPERS" type="add">Include the sheet number in the output of XLS2CSVmra</action>
<action dev="POI-DEVELOPERS" type="fix">46043 - correctly write out HPSF properties with HWPF</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta4" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45290 - Support odd files where the POIFS header block comes after the data blocks, and is on the data blocks list</header>
<action dev="POI-DEVELOPERS" type="fix">46184 - More odd escaped date formats</action>
<action dev="POI-DEVELOPERS" type="add">Include the sheet number in the output of XLS2CSVmra</action>
<action dev="POI-DEVELOPERS" type="fix">46043 - correctly write out HPSF properties with HWPF</action>
{
document =
new POIFSDocument(name, small_blocks
- .fetchBlocks(startBlock), size);
+ .fetchBlocks(startBlock, -1), size);
}
else
{
document =
new POIFSDocument(name, big_blocks
- .fetchBlocks(startBlock), size);
+ .fetchBlocks(startBlock, -1), size);
}
while (listeners.hasNext())
{
// consume the document's data and discard it
if (property.shouldUseSmallBlocks())
{
- small_blocks.fetchBlocks(startBlock);
+ small_blocks.fetchBlocks(startBlock, -1);
}
else
{
- big_blocks.fetchBlocks(startBlock);
+ big_blocks.fetchBlocks(startBlock, -1);
}
}
}
data_blocks);
// init documents
- processProperties(SmallBlockTableReader
- .getSmallDocumentBlocks(data_blocks, properties
- .getRoot(), header_block_reader
- .getSBATStart()), data_blocks, properties.getRoot()
- .getChildren(), null);
+ processProperties(
+ SmallBlockTableReader.getSmallDocumentBlocks(
+ data_blocks, properties.getRoot(),
+ header_block_reader.getSBATStart()
+ ),
+ data_blocks,
+ properties.getRoot().getChildren(),
+ null,
+ header_block_reader.getPropertyStart()
+ );
}
/**
* @param stream the stream to be closed
private void processProperties(final BlockList small_blocks,
final BlockList big_blocks,
final Iterator properties,
- final DirectoryNode dir)
+ final DirectoryNode dir,
+ final int headerPropertiesStartAt)
throws IOException
{
while (properties.hasNext())
processProperties(
small_blocks, big_blocks,
- (( DirectoryProperty ) property).getChildren(), new_dir);
+ (( DirectoryProperty ) property).getChildren(),
+ new_dir, headerPropertiesStartAt);
}
else
{
if (property.shouldUseSmallBlocks())
{
document =
- new POIFSDocument(name, small_blocks
- .fetchBlocks(startBlock), size);
+ new POIFSDocument(name,
+ small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
+ size);
}
else
{
document =
new POIFSDocument(name,
- big_blocks.fetchBlocks(startBlock),
+ big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
size);
}
parent.createDocument(document);
_blocks = null;
_properties =
PropertyFactory
- .convertToProperties(blockList.fetchBlocks(startBlock));
+ .convertToProperties(blockList.fetchBlocks(startBlock, -1));
populatePropertyTree(( DirectoryProperty ) _properties.get(0));
}
*/
ListManagedBlock [] fetchBlocks(final int startBlock,
+ final int headerPropertiesStartBlock,
final BlockList blockList)
throws IOException
{
List blocks = new ArrayList();
int currentBlock = startBlock;
-
- while (currentBlock != POIFSConstants.END_OF_CHAIN)
- {
- blocks.add(blockList.remove(currentBlock));
- currentBlock = _entries.get(currentBlock);
+ boolean firstPass = true;
+
+ // Process the chain from the start to the end
+ // Normally we have header, data, end
+ // Sometimes we have data, header, end
+ // For those cases, stop at the header, not the end
+ while (currentBlock != POIFSConstants.END_OF_CHAIN) {
+ try {
+ blocks.add(blockList.remove(currentBlock));
+ currentBlock = _entries.get(currentBlock);
+ } catch(IOException e) {
+ if(currentBlock == headerPropertiesStartBlock) {
+ // Special case where things are in the wrong order
+ System.err.println("Warning, header block comes after data blocks in POIFS block listing");
+ currentBlock = POIFSConstants.END_OF_CHAIN;
+ } else {
+ // Ripple up
+ throw e;
+ }
+ }
}
+
return ( ListManagedBlock [] ) blocks
.toArray(new ListManagedBlock[ 0 ]);
}
* blocks are removed from the list.
*
* @param startBlock the index of the first block in the stream
+ * @param headerPropertiesStartBlock the index of the first header block in the stream
*
* @return the stream as an array of correctly ordered blocks
*
* @exception IOException if blocks are missing
*/
- public ListManagedBlock [] fetchBlocks(final int startBlock)
+ public ListManagedBlock [] fetchBlocks(final int startBlock, final int headerPropertiesStartBlock)
throws IOException;
/**
result = _blocks[ index ];
if (result == null)
{
- throw new IOException("block[ " + index
- + " ] already removed");
+ throw new IOException(
+ "block[ " + index + " ] already removed - " +
+ "does your POIFS have circular or duplicate block references?"
+ );
}
_blocks[ index ] = null;
}
* @exception IOException if blocks are missing
*/
- public ListManagedBlock [] fetchBlocks(final int startBlock)
+ public ListManagedBlock [] fetchBlocks(final int startBlock, final int headerPropertiesStartBlock)
throws IOException
{
if (_bat == null)
throw new IOException(
"Improperly initialized list: no block allocation table provided");
}
- return _bat.fetchBlocks(startBlock, this);
+ return _bat.fetchBlocks(startBlock, headerPropertiesStartBlock, this);
}
/**
{
BlockList list =
new SmallDocumentBlockList(SmallDocumentBlock
- .extract(blockList.fetchBlocks(root.getStartBlock())));
+ .extract(blockList.fetchBlocks(root.getStartBlock(), -1)));
- new BlockAllocationTableReader(blockList.fetchBlocks(sbatStart),
+ new BlockAllocationTableReader(blockList.fetchBlocks(sbatStart, -1),
list);
return list;
}
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-import org.apache.poi.ss.util.Region;
-import org.apache.poi.ss.util.CellRangeAddress;
-
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.TempFile;
/**
assertEquals(7, wb.getNumberOfSheets());
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
}
+
+ /**
+ * Odd POIFS blocks issue:
+ * block[ 44 ] already removed from org.apache.poi.poifs.storage.BlockListImpl.remove
+ */
+ public void test45290() {
+ HSSFWorkbook wb = openSample("45290.xls");
+ assertEquals(1, wb.getNumberOfSheets());
+ }
}
try
{
ListManagedBlock[] dataBlocks =
- table.fetchBlocks(start_blocks[ j ], list);
+ table.fetchBlocks(start_blocks[ j ], -1, list);
if (expected_length[ j ] == -1)
{
try
{
ListManagedBlock[] dataBlocks =
- list.fetchBlocks(start_blocks[ j ]);
+ list.fetchBlocks(start_blocks[ j ], -1);
if (expected_length[ j ] == -1)
{