Bug 57851

Summary: NPE in NPOIFSFileSystem for corrupted MSG file
Product: POI Reporter: Marcin Łoś <losiu99>
Component: POIFSAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.11-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Problematic file

Description Marcin Łoś 2015-04-23 11:28:09 UTC
Created attachment 32682 [details]
Problematic file

Constructor of NPOIFSFileSystem throws NPE when given an input stream to a file created by slightly modifying valid MSG file.

@Test
public void shouldNotThrowNPE() throws IOException {
    InputStream input = ClassLoader.getSystemResourceAsStream("corrupted.msg");
    new NPOIFSFileSystem(input);
}

Resulting stack trace (removed JUnit frames):

java.lang.NullPointerException
	at org.apache.poi.poifs.property.DirectoryProperty.addChild(DirectoryProperty.java:256)
	at org.apache.poi.poifs.property.PropertyTableBase.populatePropertyTree(PropertyTableBase.java:115)
	at org.apache.poi.poifs.property.PropertyTableBase.populatePropertyTree(PropertyTableBase.java:118)
	at org.apache.poi.poifs.property.PropertyTableBase.<init>(PropertyTableBase.java:63)
	at org.apache.poi.poifs.property.NPropertyTable.<init>(NPropertyTable.java:66)
	at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.readCoreContents(NPOIFSFileSystem.java:416)
	at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:324)
	at pl.edu.agh.seeker.extractor.mail.MsgExtractorTest.shouldNotThrowNPE(MsgExtractorTest.java:24)

The culprit seems to be org.apache.poi.poifs.property.PropertyFactory.convertToProperties, which adds null to the list of properties upon encountering unrecognized property type.
Comment 1 Nick Burch 2015-04-23 18:35:55 UTC
Thanks for the investigation and the small test file! Fixed in r1675702.