[bug-66590] Update the number of property blocks in the POIFS header block

This commit is contained in:
Emmanuel Bourg 2023-05-03 09:43:02 +02:00
parent 0cd653d8c0
commit bc799b2971
5 changed files with 32 additions and 1 deletions

View File

@ -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 {

View File

@ -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,22 @@ public final class HeaderBlock implements HeaderBlockConstants {
+ read + type + " read; expected 512 bytes");
}
/**
* @return the number of property blocks
*/
public int getPropertyCount() {
return _property_count;
}
/**
* Set the number of property blocks
*
* @param _property_count number of property blocks
*/
public void setPropertyCount(int _property_count) {
this._property_count = _property_count;
}
/**
* get start of Property Table
*
@ -367,6 +389,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);

View File

@ -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;

View File

@ -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());

View File

@ -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