Skip to content

Commit 8c77000

Browse files
committed
[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
1 parent 0f42425 commit 8c77000

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public POIFSBigBlockSize getBigBlockSize() {
392392
public void writeData(final OutputStream stream) throws IOException {
393393
// Update the counts and start positions
394394
new IntegerField(_bat_count_offset, _bat_count, _data);
395-
new IntegerField(_property_count_offset, _property_count, _data);
395+
new IntegerField(_property_count_offset, bigBlockSize.getBigBlockSize() == 512 ? 0 : _property_count, _data);
396396
new IntegerField(_property_start_offset, _property_start, _data);
397397
new IntegerField(_sbat_start_offset, _sbat_start, _data);
398398
new IntegerField(_sbat_block_count_offset, _sbat_count, _data);

poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ void createWriteRead() throws IOException {
21252125
// Check the header has the right points in it
21262126
assertEquals(1, header.getBATCount());
21272127
assertEquals(1, header.getBATArray()[0]);
2128-
assertEquals(2, header.getPropertyCount());
2128+
assertEquals(0, header.getPropertyCount());
21292129
assertEquals(0, header.getPropertyStart());
21302130
assertEquals(1, header.getSBATCount());
21312131
assertEquals(21, header.getSBATStart());
@@ -2236,7 +2236,7 @@ void addBeforeWrite() throws IOException {
22362236
// Will have fat then properties stream
22372237
assertEquals(1, hdr.getBATCount());
22382238
assertEquals(1, hdr.getBATArray()[0]);
2239-
assertEquals(1, hdr.getPropertyCount());
2239+
assertEquals(0, hdr.getPropertyCount());
22402240
assertEquals(0, hdr.getPropertyStart());
22412241
assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getSBATStart());
22422242
assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
@@ -2295,7 +2295,7 @@ void addBeforeWrite() throws IOException {
22952295
assertEquals(1, hdr.getBATCount());
22962296
assertEquals(1, hdr.getBATArray()[0]);
22972297
assertEquals(2, hdr.getSBATStart());
2298-
assertEquals(2, hdr.getPropertyCount());
2298+
assertEquals(0, hdr.getPropertyCount());
22992299
assertEquals(0, hdr.getPropertyStart());
23002300
assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
23012301

@@ -2494,6 +2494,38 @@ void writeZeroLengthEntries() throws IOException {
24942494
}
24952495
}
24962496

2497+
/**
2498+
* Test that the property count is always 0 when writing files with a block size of 512 bytes.
2499+
*/
2500+
@Test
2501+
void testWritePropertyCount512() throws Exception {
2502+
try (POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"))) {
2503+
assertEquals(0, fs.getHeaderBlock().getPropertyCount(), "Property count");
2504+
2505+
for (int i = 1; i <= 100; i++) {
2506+
fs.getRoot().createOrUpdateDocument("Entry " + i, new ByteArrayInputStream(new byte[8192]));
2507+
}
2508+
2509+
assertEquals(0, writeOutAndReadBack(fs).getHeaderBlock().getPropertyCount(), "Property count");
2510+
}
2511+
}
2512+
2513+
/**
2514+
* Test that the property count is updated when writing files with a block size of 4096 bytes.
2515+
*/
2516+
@Test
2517+
void testWritePropertyCount4096() throws Exception {
2518+
try (POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"))) {
2519+
assertEquals(0, fs.getHeaderBlock().getPropertyCount(), "Property count");
2520+
2521+
for (int i = 1; i <= 100; i++) {
2522+
fs.getRoot().createOrUpdateDocument("Entry " + i, new ByteArrayInputStream(new byte[8192]));
2523+
}
2524+
2525+
assertEquals(5, writeOutAndReadBack(fs).getHeaderBlock().getPropertyCount(), "Property count");
2526+
}
2527+
}
2528+
24972529
/**
24982530
* Test that we can read a file with POIFS, create a new POIFS instance,
24992531
* write it out, read it with POIFS, and see the original data

0 commit comments

Comments
 (0)