From 4cc1544708eff4b3137b0022a868cf47986b92d5 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 11 May 2015 17:53:59 +0000 Subject: [PATCH] Correct zero byte entry support in NPOIFS git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678778 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/poifs/filesystem/NPOIFSDocument.java | 6 +++++- .../apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java index 7846ed0dfc..9492c25983 100644 --- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java +++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java @@ -143,8 +143,12 @@ public final class NPOIFSDocument implements POIFSViewable { os.write(buf, 0, readBytes); } - os.close(); + // If this is an empty document, write a single byte + // to force a block allocation for this document + if (length == 0) os.write(0); + // Tidy and return the length + os.close(); return length; } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java index b4e3b79af4..1444374833 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java @@ -41,7 +41,6 @@ import org.apache.poi.poifs.property.Property; import org.apache.poi.poifs.property.RootProperty; import org.apache.poi.poifs.storage.HeaderBlock; import org.apache.poi.util.IOUtils; -import org.junit.Ignore; import org.junit.Test; /** @@ -1307,7 +1306,6 @@ public final class TestNPOIFSFileSystem { assertContentsMatches(main4106, normDoc); } - @Ignore @Test public void writeZeroLengthEntries() throws Exception { NPOIFSFileSystem fs = new NPOIFSFileSystem(); @@ -1350,6 +1348,7 @@ public final class TestNPOIFSFileSystem { // Save and re-check fs = writeOutAndReadBack(fs); + testDir = fs.getRoot(); miniDoc = (DocumentEntry)testDir.getEntry("Mini2"); assertContentsMatches(mini2, miniDoc); -- 2.39.5