aboutsummaryrefslogtreecommitdiffstats
path: root/poi/src/main
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-11-27 13:32:39 +0000
committerPJ Fanning <fanningpj@apache.org>2024-11-27 13:32:39 +0000
commitd4c6cb4b53d9aeadfc44f6b1dcf3657bc149dc68 (patch)
tree00c2aceba6ec33390c21a7a0ca9d45c770dab901 /poi/src/main
parent6fdbaa55f387ea3927512412eadd569a67973a61 (diff)
downloadpoi-d4c6cb4b53d9aeadfc44f6b1dcf3657bc149dc68.tar.gz
poi-d4c6cb4b53d9aeadfc44f6b1dcf3657bc149dc68.zip
add back 731 changes but increase gradle heap
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1922162 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi/src/main')
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java29
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