From ac7b4bc3dd6f5212b6c752c6bf8b16aec55c1691 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 23 Apr 2015 18:35:15 +0000 Subject: [PATCH] #57851 - Skip null properties in PropertyTableBase, which is how PropertyFactory reports unsupported POIFS properties git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1675702 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/poifs/property/PropertyTableBase.java | 5 ++++ .../poifs/filesystem/TestFileSystemBugs.java | 30 +++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/poi/poifs/property/PropertyTableBase.java b/src/java/org/apache/poi/poifs/property/PropertyTableBase.java index b3690c5c24..477cf036d8 100644 --- a/src/java/org/apache/poi/poifs/property/PropertyTableBase.java +++ b/src/java/org/apache/poi/poifs/property/PropertyTableBase.java @@ -111,6 +111,11 @@ public abstract class PropertyTableBase implements BATManaged { while (!children.empty()) { Property property = children.pop(); + if (property == null) + { + // unknown / unsupported / corrupted property, skip + continue; + } root.addChild(property); if (property.isDirectory()) diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java index 6033e0e494..f6540b4d30 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java @@ -44,15 +44,22 @@ public final class TestFileSystemBugs extends TestCase { } openedFSs = null; } - protected DirectoryNode[] openSample(String name) throws Exception { - POIFSFileSystem ofs = new POIFSFileSystem( - _samples.openResourceAsStream(name)); + protected DirectoryNode[] openSample(String name, boolean oldFails) throws Exception { NPOIFSFileSystem nfs = new NPOIFSFileSystem( _samples.openResourceAsStream(name)); - if (openedFSs == null) openedFSs = new ArrayList(); openedFSs.add(nfs); + POIFSFileSystem ofs = null; + try { + ofs = new POIFSFileSystem( + _samples.openResourceAsStream(name)); + if (oldFails) fail("POIFSFileSystem should have failed but didn't"); + } catch (Exception e) { + if (!oldFails) throw e; + } + + if (ofs == null) return new DirectoryNode[] { nfs.getRoot() }; return new DirectoryNode[] { ofs.getRoot(), nfs.getRoot() }; } @@ -62,7 +69,7 @@ public final class TestFileSystemBugs extends TestCase { */ public void testNotesOLE2Files() throws Exception { // Check the contents - for (DirectoryNode root : openSample("Notes.ole2")) { + for (DirectoryNode root : openSample("Notes.ole2", false)) { assertEquals(1, root.getEntryCount()); Entry entry = root.getEntries().next(); @@ -87,4 +94,17 @@ public final class TestFileSystemBugs extends TestCase { assertEquals("\u0001CompObj", entry.getName()); } } + + /** + * Ensure that a file with a corrupted property in the + * properties table can still be loaded, and the remaining + * properties used + * Note - only works for NPOIFSFileSystem, POIFSFileSystem + * can't cope with this level of corruption + */ + public void testCorruptedProperties() throws Exception { + for (DirectoryNode root : openSample("unknown_properties.msg", true)) { + assertEquals(42, root.getEntryCount()); + } + } }