Skip to content

Commit

Permalink
[bug-66590] Set the number of blocks used by the property table in th…
Browse files Browse the repository at this point in the history
…e header of files using 4096 byte blocks only (#462)
  • Loading branch information
ebourg committed Nov 19, 2024
1 parent 0aa9e2b commit 83b1470
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public POIFSBigBlockSize getBigBlockSize() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ void createWriteRead() throws IOException {
// 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());
Expand Down Expand Up @@ -2236,7 +2236,7 @@ void addBeforeWrite() throws IOException {
// 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());
Expand Down Expand Up @@ -2295,7 +2295,7 @@ void addBeforeWrite() throws IOException {
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());

Expand Down Expand Up @@ -2494,6 +2494,38 @@ void writeZeroLengthEntries() throws IOException {
}
}

/**
* 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
Expand Down

0 comments on commit 83b1470

Please sign in to comment.