From: Nick Burch Date: Mon, 6 Jul 2015 21:39:42 +0000 (+0000) Subject: When writing the mini-stream, set the size of it on the root property #58061 X-Git-Tag: REL_3_13_BETA1~62 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d1bcdb0bcdd4e3a6e74b33a18f5dc4b619a0e640;p=poi.git When writing the mini-stream, set the size of it on the root property #58061 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1689505 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java b/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java index 54ab231493..e321c8b9b7 100644 --- a/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java +++ b/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java @@ -160,6 +160,7 @@ public class POIFSHeaderDumper { public static void displayPropertiesSummary(PropertyTable properties) { System.out.println("Mini Stream starts at " + properties.getRoot().getStartBlock()); + System.out.println("Mini Stream length is " + properties.getRoot().getSize()); System.out.println(); System.out.println("Properties and their block start:"); diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java index f7e19137a6..c27ba3cd14 100644 --- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java @@ -766,6 +766,10 @@ public class NPOIFSFileSystem extends BlockStore * to their backing blocks */ private void syncWithDataSource() throws IOException { + // Mini Stream + SBATs first, as mini-stream details have + // to be stored in the Root Property + _mini_store.syncWithDataSource(); + // Properties NPOIFSStream propStream = new NPOIFSStream(this, _header.getPropertyStart()); _property_table.preWrite(); @@ -786,9 +790,6 @@ public class NPOIFSFileSystem extends BlockStore ByteBuffer block = getBlockAt(bat.getOurBlockIndex()); BlockAllocationTableWriter.writeBlock(bat, block); } - - // SBATs - _mini_store.syncWithDataSource(); } /** diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java index 308ae15c74..b784058bc5 100644 --- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java +++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java @@ -242,12 +242,24 @@ public class NPOIFSMiniStore extends BlockStore } /** - * Writes the SBATs to their backing blocks + * Writes the SBATs to their backing blocks, and updates + * the mini-stream size in the properties. Stream size is + * based on full blocks used, not the data within the streams */ protected void syncWithDataSource() throws IOException { - for(BATBlock sbat : _sbat_blocks) { + int blocksUsed = 0; + for (BATBlock sbat : _sbat_blocks) { ByteBuffer block = _filesystem.getBlockAt(sbat.getOurBlockIndex()); BlockAllocationTableWriter.writeBlock(sbat, block); + + if (!sbat.hasFreeSectors()) { + blocksUsed += _filesystem.getBigBlockSizeDetails().getBATEntriesPerBlock(); + } else { + blocksUsed += sbat.getUsedSectors(false); + } } + // 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); } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java index a476233ec7..ed598ed6cc 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java @@ -1428,6 +1428,10 @@ public final class TestNPOIFSFileSystem { emptyDoc = (DocumentEntry)testDir.getEntry("empty-3"); assertContentsMatches(empty, emptyDoc); + // Check that a mini-stream was assigned, with one block used + assertEquals(3, testDir.getProperty().getStartBlock()); + assertEquals(64, testDir.getProperty().getSize()); + // All done fs.close(); }