diff options
author | PJ Fanning <fanningpj@apache.org> | 2024-11-25 19:33:17 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2024-11-25 19:33:17 +0000 |
commit | 0d63f9a814f14717a5d9e0f51d79714fc0438417 (patch) | |
tree | 6336af8cfeda8e242ed43020226aec5082749740 /poi/src/main/java | |
parent | 799aef54fe589ac518a11ae38408c712fa7ef39a (diff) | |
download | poi-0d63f9a814f14717a5d9e0f51d79714fc0438417.tar.gz poi-0d63f9a814f14717a5d9e0f51d79714fc0438417.zip |
[github-731] Fix the mini-stream size in the root property. This closes #731
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1922094 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi/src/main/java')
-rw-r--r-- | poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java index 18cdfd58f7..cb1929d0d6 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java @@ -247,20 +247,33 @@ public class POIFSMiniStore extends BlockStore { * based on full blocks used, not the data within the streams */ void syncWithDataSource() throws IOException { - int blocksUsed = 0; for (BATBlock sbat : _sbat_blocks) { ByteBuffer block = _filesystem.getBlockAt(sbat.getOurBlockIndex()); sbat.writeData(block); - - if (!sbat.hasFreeSectors()) { - blocksUsed += _filesystem.getBigBlockSizeDetails().getBATEntriesPerBlock(); - } else { - blocksUsed += sbat.getOccupiedSize(); - } } + // Set the size on the root in terms of the number of SBAT blocks // RootProperty.setSize does the sbat -> bytes conversion for us - _filesystem._get_property_table().getRoot().setSize(blocksUsed); + _filesystem._get_property_table().getRoot().setSize(computeSize()); + } + + /** + * Computes the size of the mini-stream (in number of mini blocks). The trailing + * unallocated mini blocks are ignored, the others are counted as allocated. This + * behaviour was checked with MSI files signed with signtool. + */ + private int computeSize() { + int entriesPerBlock = _filesystem.getBigBlockSizeDetails().getBATEntriesPerBlock(); + for (int sbatIndex = _sbat_blocks.size() - 1; sbatIndex >= 0; sbatIndex--) { + BATBlock sbat = _sbat_blocks.get(sbatIndex); + for (int miniBlockIndex = entriesPerBlock - 1; miniBlockIndex >= 0; miniBlockIndex--) { + if (sbat.getValueAt(miniBlockIndex) != POIFSConstants.UNUSED_BLOCK) { + return (sbatIndex * entriesPerBlock) + miniBlockIndex + 1; + } + } + } + + return 0; } @Override |