From 7a2a057c86e2b053e57f7d9ebdff9710eff3c1a4 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sun, 18 Oct 2020 22:24:16 +0000 Subject: #64817 - Fix issue in testXLSXinPPT git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882623 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/extractor/ExtractorFactory.java | 14 ++++++++------ src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java | 5 +++-- src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java | 12 ++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'src/java') diff --git a/src/java/org/apache/poi/extractor/ExtractorFactory.java b/src/java/org/apache/poi/extractor/ExtractorFactory.java index 6b3ec00df6..a908a73085 100644 --- a/src/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/src/java/org/apache/poi/extractor/ExtractorFactory.java @@ -17,7 +17,7 @@ package org.apache.poi.extractor; import static org.apache.poi.hssf.record.crypto.Biff8EncryptionKey.getCurrentUserPassword; -import static org.apache.poi.poifs.crypt.EncryptionInfo.ENCRYPTION_INFO_ENTRY; +import static org.apache.poi.poifs.crypt.Decryptor.DEFAULT_POIFS_ENTRY; import java.io.File; import java.io.IOException; @@ -168,9 +168,10 @@ public final class ExtractorFactory { } POIFSFileSystem poifs = new POIFSFileSystem(is); - boolean isOOXML = poifs.getRoot().hasEntry(ENCRYPTION_INFO_ENTRY); + DirectoryNode root = poifs.getRoot(); + boolean isOOXML = root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE); - return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(poifs.getRoot(), password)); + return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(root, password)); } public static POITextExtractor createExtractor(File file) throws IOException { @@ -193,8 +194,9 @@ public final class ExtractorFactory { POIFSFileSystem poifs = new POIFSFileSystem(file, true); try { - boolean isOOXML = poifs.getRoot().hasEntry(ENCRYPTION_INFO_ENTRY); - return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(poifs.getRoot(), password)); + DirectoryNode root = poifs.getRoot(); + boolean isOOXML = root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE); + return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(root, password)); } catch (IOException | RuntimeException e) { IOUtils.closeQuietly(poifs); throw e; @@ -223,7 +225,7 @@ public final class ExtractorFactory { public static POITextExtractor createExtractor(final DirectoryNode root, String password) throws IOException { // Encrypted OOXML files go inside OLE2 containers, is this one? - if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) { + if (root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) { return wp(FileMagic.OOXML, w -> w.create(root, password)); } else { return wp(FileMagic.OLE2, w -> w.create(root, password)); diff --git a/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java b/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java index 83d3ae6e70..a69efaf8f8 100644 --- a/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java +++ b/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java @@ -17,7 +17,7 @@ package org.apache.poi.sl.usermodel; import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE; -import static org.apache.poi.poifs.crypt.EncryptionInfo.ENCRYPTION_INFO_ENTRY; +import static org.apache.poi.poifs.crypt.Decryptor.DEFAULT_POIFS_ENTRY; import java.io.BufferedInputStream; import java.io.File; @@ -198,7 +198,8 @@ public final class SlideShowFactory { } POIFSFileSystem poifs = new POIFSFileSystem(is); - boolean isOOXML = poifs.getRoot().hasEntry(ENCRYPTION_INFO_ENTRY); + DirectoryNode root = poifs.getRoot(); + boolean isOOXML = root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE); return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(poifs.getRoot(), password)); } diff --git a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java index ede792368a..c0f376f65f 100644 --- a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java +++ b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java @@ -17,7 +17,7 @@ package org.apache.poi.ss.usermodel; import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE; -import static org.apache.poi.poifs.crypt.EncryptionInfo.ENCRYPTION_INFO_ENTRY; +import static org.apache.poi.poifs.crypt.Decryptor.DEFAULT_POIFS_ENTRY; import java.io.BufferedInputStream; import java.io.File; @@ -31,7 +31,6 @@ import java.util.ServiceLoader; import org.apache.poi.EmptyFileException; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.poifs.filesystem.POIFSFileSystem; @@ -132,7 +131,7 @@ public final class WorkbookFactory { */ public static Workbook create(final DirectoryNode root, String password) throws IOException { // Encrypted OOXML files go inside OLE2 containers, is this one? - if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) { + if (root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) { return wp(FileMagic.OOXML, w -> w.create(root, password)); } else { return wp(FileMagic.OLE2, w -> w.create(root, password)); @@ -205,9 +204,10 @@ public final class WorkbookFactory { } POIFSFileSystem poifs = new POIFSFileSystem(is); - boolean isOOXML = poifs.getRoot().hasEntry(ENCRYPTION_INFO_ENTRY); + DirectoryNode root = poifs.getRoot(); + boolean isOOXML = root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE); - return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(poifs.getRoot(), password)); + return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(root, password)); } /** @@ -279,7 +279,7 @@ public final class WorkbookFactory { final boolean ooxmlEnc; try (POIFSFileSystem fs = new POIFSFileSystem(file, true)) { DirectoryNode root = fs.getRoot(); - ooxmlEnc = root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE); + ooxmlEnc = root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE); } return wp(ooxmlEnc ? FileMagic.OOXML : fm, w -> w.create(file, password, readOnly)); } -- cgit v1.2.3