Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions msgparser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@
<version>6.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
6 changes: 3 additions & 3 deletions msgparser/src/main/java/com/auxilii/msgparser/MsgParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static Message parseMsg(DirectoryEntry dir) throws IOException {
DirectoryEntry entry = (DirectoryEntry) dir.getEntry(String.format("__attach_version1.0_#%08X", index));
msg.addAttachment(parseAttachment(entry));
}
while (propertyStream.available() > 0) {
while (propertyStream.available() >= 8) {
msg.setProperty(new Property(propertyStream, dir));
}
return msg;
Expand Down Expand Up @@ -113,7 +113,7 @@ private static Attachment parseAttachment(DirectoryEntry dir) throws IOException
if (dir.hasEntry(Ptyp.SUBSTORAGE_PREFIX + "3701000D")) {
return parseEmbeddedMessage(dir);
}
return ParseFileAttachment(dir);
return parseFileAttachment(dir);
}

private static MsgAttachment parseEmbeddedMessage(DirectoryEntry dir) throws IOException {
Expand All @@ -122,7 +122,7 @@ private static MsgAttachment parseEmbeddedMessage(DirectoryEntry dir) throws IOE
return new MsgAttachment(parseMsg(entry));
}

private static FileAttachment ParseFileAttachment(DirectoryEntry dir) throws IOException {
private static FileAttachment parseFileAttachment(DirectoryEntry dir) throws IOException {
DocumentEntry propertyEntry = (DocumentEntry) dir.getEntry(PROPERTIES_ENTRY);
try (DocumentInputStream propertyStream = new DocumentInputStream(propertyEntry)) {
propertyStream.skip(8);
Expand Down
37 changes: 37 additions & 0 deletions msgparser/src/test/java/com/auxilii/msgparser/MsgParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.auxilii.msgparser;

import static org.junit.jupiter.api.Assertions.*;

import com.google.common.jimfs.Jimfs;
import java.io.*;
import java.nio.file.*;
import org.apache.poi.poifs.filesystem.*;
import org.junit.jupiter.api.Test;

class MsgParserTest {
@Test
void should_ignore_trailing_bytes() throws IOException {
try (FileSystem fileSystem = Jimfs.newFileSystem()) {
Path messagePath = fileSystem.getPath("message.msg");
writeMessageWithTrailingBytes(messagePath);
MsgParser parser = new MsgParser(messagePath);
assertDoesNotThrow(parser::parseMsg);
}
}

private static void writeMessageWithTrailingBytes(Path target) throws IOException {
try (POIFSFileSystem fs = new POIFSFileSystem()) {
byte[] content = {
0,0,0,0,0,0,0,0, // reserved
0,0,0,0, // nextRecipientId
0,0,0,0, // nextAttachmentId
0,0,0,0, // recipientCount
0,0,0,0, // attachmentCount
0,0,0,0,0,0,0,0, // reserved for top level message
1,2,3,4 // trailing garbage
};
fs.getRoot().createDocument("__properties_version1.0", new ByteArrayInputStream(content));
fs.writeFilesystem(Files.newOutputStream(target));
}
}
}