aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java3
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java43
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java1
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java3
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/storage/TestHeaderBlockReading.java3
5 files changed, 44 insertions, 9 deletions
diff --git a/poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java b/poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java
index 5e9565da87..cb636971dd 100644
--- a/poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java
+++ b/poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java
@@ -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 {
diff --git a/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java b/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
index 44d31728c6..99068904b5 100644
--- a/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
+++ b/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
@@ -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();
@@ -227,6 +233,25 @@ public final class HeaderBlock implements HeaderBlockConstants {
}
/**
+ * @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
*
* @return the index of the first block of the 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);
diff --git a/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java b/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java
index a029505ac3..2cb5e503c4 100644
--- a/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java
+++ b/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java
@@ -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;
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
index 0b97d8eb8c..217eda34d3 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
@@ -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());
diff --git a/poi/src/test/java/org/apache/poi/poifs/storage/TestHeaderBlockReading.java b/poi/src/test/java/org/apache/poi/poifs/storage/TestHeaderBlockReading.java
index 009eac6cc6..3fb4dfe5ad 100644
--- a/poi/src/test/java/org/apache/poi/poifs/storage/TestHeaderBlockReading.java
+++ b/poi/src/test/java/org/apache/poi/poifs/storage/TestHeaderBlockReading.java
@@ -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