diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2018-11-25 20:50:13 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2018-11-25 20:50:13 +0000 |
commit | 283ebe0e08755828effc71c0afe314786e75ce86 (patch) | |
tree | 58fc2f6db358652f213fada8068e529e47e563bd /src/java/org/apache/poi/poifs/filesystem | |
parent | d2cf03d353e62f417b5685c696ab4c6e50550811 (diff) | |
download | poi-283ebe0e08755828effc71c0afe314786e75ce86.tar.gz poi-283ebe0e08755828effc71c0afe314786e75ce86.zip |
#62951 - FileMagic not correctly identified
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1847429 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/poifs/filesystem')
-rw-r--r-- | src/java/org/apache/poi/poifs/filesystem/FileMagic.java | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/java/org/apache/poi/poifs/filesystem/FileMagic.java b/src/java/org/apache/poi/poifs/filesystem/FileMagic.java index 4ac616082e..bab62c6437 100644 --- a/src/java/org/apache/poi/poifs/filesystem/FileMagic.java +++ b/src/java/org/apache/poi/poifs/filesystem/FileMagic.java @@ -78,7 +78,7 @@ public enum FileMagic { /** PDF document */ PDF("%PDF"), /** Some different HTML documents */ - HTML("<!DOCTYP".getBytes(UTF_8), "<html".getBytes(UTF_8)), + HTML("<!DOCTYP".getBytes(UTF_8), "<html".getBytes(UTF_8), "<HTML".getBytes(UTF_8)), WORD2(new byte[]{ (byte)0xdb, (byte)0xa5, 0x2d, 0x00}), // keep UNKNOWN always as last enum! /** UNKNOWN magic */ @@ -101,17 +101,8 @@ public enum FileMagic { public static FileMagic valueOf(byte[] magic) { for (FileMagic fm : values()) { - int i=0; - boolean found = true; for (byte[] ma : fm.magic) { - for (byte m : ma) { - byte d = magic[i++]; - if (!(d == m || (m == 0x70 && (d == 0x10 || d == 0x20 || d == 0x40)))) { - found = false; - break; - } - } - if (found) { + if (findMagic(ma, magic)) { return fm; } } @@ -119,6 +110,17 @@ public enum FileMagic { return UNKNOWN; } + private static boolean findMagic(byte[] cmp, byte[] actual) { + int i=0; + for (byte m : cmp) { + byte d = actual[i++]; + if (!(d == m || (m == 0x70 && (d == 0x10 || d == 0x20 || d == 0x40)))) { + return false; + } + } + return true; + } + /** * Get the file magic of the supplied {@link File}<p> |