diff options
author | PJ Fanning <fanningpj@apache.org> | 2024-11-19 17:39:09 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2024-11-19 17:39:09 +0000 |
commit | 8c77000e8d0f26ac67cefd1532f3fe464d5983c1 (patch) | |
tree | 9296bfce7a9ce6a290c4cfaebe1192268a254d4b | |
parent | 0f42425f8cc577edfdf283de89c86ac349520ffa (diff) | |
download | poi-8c77000e8d0f26ac67cefd1532f3fe464d5983c1.tar.gz poi-8c77000e8d0f26ac67cefd1532f3fe464d5983c1.zip |
[bug-66590] Number of blocks used by the property table missing from the file header. Thanks to Emmanuel Bourg. This closes #728
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921956 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java | 2 | ||||
-rw-r--r-- | poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java | 38 |
2 files changed, 36 insertions, 4 deletions
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 e683fe35a5..8b6512d3f2 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 @@ -392,7 +392,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_count_offset, bigBlockSize.getBigBlockSize() == 512 ? 0 : _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/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java index 217eda34d3..dcbf5145a0 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,7 +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.getPropertyCount()); assertEquals(0, header.getPropertyStart()); assertEquals(1, header.getSBATCount()); assertEquals(21, header.getSBATStart()); @@ -2236,7 +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.getPropertyCount()); assertEquals(0, hdr.getPropertyStart()); assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getSBATStart()); assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex()); @@ -2295,7 +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.getPropertyCount()); assertEquals(0, hdr.getPropertyStart()); assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex()); @@ -2495,6 +2495,38 @@ final class TestPOIFSStream { } /** + * Test that the property count is always 0 when writing files with a block size of 512 bytes. + */ + @Test + void testWritePropertyCount512() throws Exception { + try (POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"))) { + assertEquals(0, fs.getHeaderBlock().getPropertyCount(), "Property count"); + + for (int i = 1; i <= 100; i++) { + fs.getRoot().createOrUpdateDocument("Entry " + i, new ByteArrayInputStream(new byte[8192])); + } + + assertEquals(0, writeOutAndReadBack(fs).getHeaderBlock().getPropertyCount(), "Property count"); + } + } + + /** + * Test that the property count is updated when writing files with a block size of 4096 bytes. + */ + @Test + void testWritePropertyCount4096() throws Exception { + try (POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"))) { + assertEquals(0, fs.getHeaderBlock().getPropertyCount(), "Property count"); + + for (int i = 1; i <= 100; i++) { + fs.getRoot().createOrUpdateDocument("Entry " + i, new ByteArrayInputStream(new byte[8192])); + } + + assertEquals(5, writeOutAndReadBack(fs).getHeaderBlock().getPropertyCount(), "Property count"); + } + } + + /** * Test that we can read a file with POIFS, create a new POIFS instance, * write it out, read it with POIFS, and see the original data */ |