Skip to content

Commit aa1561a

Browse files
paolodentiebourg
authored andcommitted
Fix the EOFException when MSIFile.isFile() is used on a file smaller than 8 bytes (Fixes ebourg#160)
1 parent f68f4da commit aa1561a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

jsign-core/src/main/java/net/jsign/msi/MSIFile.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ public class MSIFile implements Signable {
107107
* @throws IOException if an I/O error occurs
108108
*/
109109
public static boolean isMSIFile(File file) throws IOException {
110+
if (file.length() < 8) {
111+
return false;
112+
}
110113
try (DataInputStream in = new DataInputStream(new FileInputStream(file))) {
111114
return in.readLong() == MSI_HEADER;
112115
}

jsign-core/src/test/java/net/jsign/msi/MSIFileTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.File;
2020

21+
import org.apache.commons.io.FileUtils;
2122
import org.junit.Test;
2223

2324
import static org.junit.Assert.*;
@@ -28,6 +29,11 @@ public class MSIFileTest {
2829
public void testIsMSIFile() throws Exception {
2930
assertFalse(MSIFile.isMSIFile(new File("pom.xml")));
3031
assertTrue(MSIFile.isMSIFile(new File("target/test-classes/minimal.msi")));
32+
33+
// small file
34+
File file = File.createTempFile("small", ".msi");
35+
FileUtils.writeByteArrayToFile(file, new byte[3]);
36+
assertFalse(MSIFile.isMSIFile(file));
3137
}
3238

3339
@Test

0 commit comments

Comments
 (0)