mirror of https://github.com/apache/poi.git
[bug-66590] Number of blocks used by the property table missing from the file header. Thanks to Emmanuel Bourg. This closes #462
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8fe23195c6
commit
1df9b9c5cb
|
@ -219,6 +219,9 @@ public final class PropertyTable implements BATManaged {
|
|||
if(getStartBlock() != stream.getStartBlock()) {
|
||||
setStartBlock(stream.getStartBlock());
|
||||
}
|
||||
|
||||
// Update the number of property blocks in the header
|
||||
_header_block.setPropertyCount(countBlocks());
|
||||
}
|
||||
|
||||
private void populatePropertyTree(DirectoryProperty root) throws IOException {
|
||||
|
|
|
@ -57,6 +57,11 @@ public final class HeaderBlock implements HeaderBlockConstants {
|
|||
*/
|
||||
private int _bat_count;
|
||||
|
||||
/**
|
||||
* Number of property blocks (int).
|
||||
*/
|
||||
private int _property_count;
|
||||
|
||||
/**
|
||||
* Start of the property set block (int index of the property set
|
||||
* chain's first big block).
|
||||
|
@ -162,6 +167,7 @@ public final class HeaderBlock implements HeaderBlockConstants {
|
|||
|
||||
// Setup the fields to read and write the counts and starts
|
||||
_bat_count = new IntegerField(_bat_count_offset, data).get();
|
||||
_property_count = new IntegerField(_property_count_offset,_data).get();
|
||||
_property_start = new IntegerField(_property_start_offset,_data).get();
|
||||
_sbat_start = new IntegerField(_sbat_start_offset, _data).get();
|
||||
_sbat_count = new IntegerField(_sbat_block_count_offset, _data).get();
|
||||
|
@ -226,6 +232,25 @@ public final class HeaderBlock implements HeaderBlockConstants {
|
|||
+ read + type + " read; expected 512 bytes");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of property blocks
|
||||
*
|
||||
* @since POI 5.4.0
|
||||
*/
|
||||
public int getPropertyCount() {
|
||||
return _property_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of property blocks
|
||||
*
|
||||
* @param property_count number of property blocks
|
||||
* @since POI 5.4.0
|
||||
*/
|
||||
public void setPropertyCount(final int property_count) {
|
||||
this._property_count = property_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* get start of Property Table
|
||||
*
|
||||
|
@ -234,14 +259,15 @@ public final class HeaderBlock implements HeaderBlockConstants {
|
|||
public int getPropertyStart() {
|
||||
return _property_start;
|
||||
}
|
||||
/**
|
||||
* Set start of Property Table
|
||||
*
|
||||
* @param startBlock the index of the first block of the Property Table
|
||||
*/
|
||||
public void setPropertyStart(final int startBlock) {
|
||||
_property_start = startBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set start of Property Table
|
||||
*
|
||||
* @param startBlock the index of the first block of the Property Table
|
||||
*/
|
||||
public void setPropertyStart(final int startBlock) {
|
||||
_property_start = startBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return start of small block (MiniFAT) allocation table
|
||||
|
@ -367,6 +393,7 @@ public final class HeaderBlock implements HeaderBlockConstants {
|
|||
public void writeData(final OutputStream stream) throws IOException {
|
||||
// Update the counts and start positions
|
||||
new IntegerField(_bat_count_offset, _bat_count, _data);
|
||||
new IntegerField(_property_count_offset, _property_count, _data);
|
||||
new IntegerField(_property_start_offset, _property_start, _data);
|
||||
new IntegerField(_sbat_start_offset, _sbat_start, _data);
|
||||
new IntegerField(_sbat_block_count_offset, _sbat_count, _data);
|
||||
|
|
|
@ -39,6 +39,7 @@ public interface HeaderBlockConstants
|
|||
// useful offsets
|
||||
int _signature_offset = 0;
|
||||
int _bat_count_offset = 0x2C;
|
||||
int _property_count_offset = 0x28;
|
||||
int _property_start_offset = 0x30;
|
||||
int _sbat_start_offset = 0x3C;
|
||||
int _sbat_block_count_offset = 0x40;
|
||||
|
|
|
@ -2125,6 +2125,7 @@ final class TestPOIFSStream {
|
|||
// Check the header has the right points in it
|
||||
assertEquals(1, header.getBATCount());
|
||||
assertEquals(1, header.getBATArray()[0]);
|
||||
assertEquals(2, header.getPropertyCount());
|
||||
assertEquals(0, header.getPropertyStart());
|
||||
assertEquals(1, header.getSBATCount());
|
||||
assertEquals(21, header.getSBATStart());
|
||||
|
@ -2235,6 +2236,7 @@ final class TestPOIFSStream {
|
|||
// Will have fat then properties stream
|
||||
assertEquals(1, hdr.getBATCount());
|
||||
assertEquals(1, hdr.getBATArray()[0]);
|
||||
assertEquals(1, hdr.getPropertyCount());
|
||||
assertEquals(0, hdr.getPropertyStart());
|
||||
assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getSBATStart());
|
||||
assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
|
||||
|
@ -2293,6 +2295,7 @@ final class TestPOIFSStream {
|
|||
assertEquals(1, hdr.getBATCount());
|
||||
assertEquals(1, hdr.getBATArray()[0]);
|
||||
assertEquals(2, hdr.getSBATStart());
|
||||
assertEquals(2, hdr.getPropertyCount());
|
||||
assertEquals(0, hdr.getPropertyStart());
|
||||
assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ final class TestHeaderBlockReading {
|
|||
void testConstructors() throws IOException {
|
||||
String[] hexData = {
|
||||
"D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 03 00 FE FF 09 00",
|
||||
"06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FE FF FF FF 00 00 00 00 00 10 00 00 FE FF FF FF",
|
||||
"06 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 FE FF FF FF 00 00 00 00 00 10 00 00 FE FF FF FF",
|
||||
"01 00 00 00 FE FF FF FF 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
|
||||
"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
|
||||
"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
|
||||
|
@ -54,6 +54,7 @@ final class TestHeaderBlockReading {
|
|||
byte[] content = RawDataUtil.decode(hexData);
|
||||
HeaderBlock block = new HeaderBlock(new ByteArrayInputStream(content));
|
||||
|
||||
assertEquals(1, block.getPropertyCount());
|
||||
assertEquals(-2, block.getPropertyStart());
|
||||
|
||||
// verify we can't read a short block
|
||||
|
|
Loading…
Reference in New Issue