use of org.apache.poi.poifs.common.POIFSBigBlockSize in project poi by apache.
the class BATBlock method getSBATBlockAndIndex.
/**
* Returns the BATBlock that handles the specified offset,
* and the relative index within it, for the mini stream.
* The List of BATBlocks must be in sequential order
*/
public static BATBlockAndIndex getSBATBlockAndIndex(final int offset, final HeaderBlock header, final List<BATBlock> sbats) {
POIFSBigBlockSize bigBlockSize = header.getBigBlockSize();
int entriesPerBlock = bigBlockSize.getBATEntriesPerBlock();
// SBATs are so much easier, as they're chained streams
int whichSBAT = offset / entriesPerBlock;
int index = offset % entriesPerBlock;
return new BATBlockAndIndex(index, sbats.get(whichSBAT));
}
use of org.apache.poi.poifs.common.POIFSBigBlockSize in project poi by apache.
the class DocumentBlock method getDataInputBlock.
public static DataInputBlock getDataInputBlock(DocumentBlock[] blocks, int offset) {
if (blocks == null || blocks.length == 0) {
return null;
}
// Key things about the size of the block
POIFSBigBlockSize bigBlockSize = blocks[0].bigBlockSize;
int BLOCK_SHIFT = bigBlockSize.getHeaderValue();
int BLOCK_SIZE = bigBlockSize.getBigBlockSize();
int BLOCK_MASK = BLOCK_SIZE - 1;
// Now do the offset lookup
int firstBlockIndex = offset >> BLOCK_SHIFT;
int firstBlockOffset = offset & BLOCK_MASK;
return new DataInputBlock(blocks[firstBlockIndex]._data, firstBlockOffset);
}
use of org.apache.poi.poifs.common.POIFSBigBlockSize in project poi by apache.
the class TestBlockAllocationTableReader method testBadSectorAllocationTableSize_bug48085.
/**
* Bugzilla 48085 describes an error where a corrupted Excel file causes POI to throw an
* {@link OutOfMemoryError}.
*/
public void testBadSectorAllocationTableSize_bug48085() {
int BLOCK_SIZE = 512;
POIFSBigBlockSize bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
assertEquals(BLOCK_SIZE, bigBlockSize.getBigBlockSize());
// 512 bytes take from the start of bugzilla attachment 24444
byte[] initData = HexRead.readFromString("D0 CF 11 E0 A1 B1 1A E1 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 3E 20 03 20 FE FF 09 20" + "06 20 20 20 20 20 20 20 20 20 20 20 01 20 20 20 01 20 20 20 20 20 20 20 20 10 20 20 02 20 20 20" + "02 20 20 20 FE FF FF FF 20 20 20 20 20 20 20 20 ");
// the rest of the block is 'FF'
byte[] data = new byte[BLOCK_SIZE];
Arrays.fill(data, (byte) 0xFF);
System.arraycopy(initData, 0, data, 0, initData.length);
// similar code to POIFSFileSystem.<init>:
InputStream stream = new ByteArrayInputStream(data);
HeaderBlock hb;
RawDataBlockList dataBlocks;
try {
hb = new HeaderBlock(stream);
dataBlocks = new RawDataBlockList(stream, bigBlockSize);
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
new BlockAllocationTableReader(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, hb.getBATCount(), hb.getBATArray(), hb.getXBATCount(), hb.getXBATIndex(), dataBlocks);
} catch (IOException e) {
// expected during successful test
assertEquals("Block count 538976257 is too high. POI maximum is 65535.", e.getMessage());
} catch (OutOfMemoryError e) {
if (e.getStackTrace()[1].getMethodName().equals("testBadSectorAllocationTableSize")) {
throw new AssertionFailedError("Identified bug 48085");
}
}
}
Aggregations