From b4c92e4ae504e4d11b5e1e4fc15a7244568f539c Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 1 Jul 2022 16:30:15 +0000 Subject: [PATCH] [bug-65634] NotOLE2FileException not thrown in POI 5.0.0 by opening an XML-RAW File with SlideShowFactory.create() git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902395 13f79535-47bb-0310-9956-ffa450edef68 --- .../usermodel/TestXSLFSlideShowFactory.java | 26 ++++++++++++++++ .../usermodel/TestHSLFSlideShowFactory.java | 31 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java index 89436fcbf0..a51f1838e8 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java @@ -20,8 +20,10 @@ package org.apache.poi.xslf.usermodel; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -34,8 +36,11 @@ import org.apache.poi.poifs.crypt.EncryptionMode; import org.apache.poi.poifs.crypt.Encryptor; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.sl.usermodel.BaseTestSlideShowFactory; +import org.apache.poi.sl.usermodel.SlideShow; +import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.util.IOUtils; import org.apache.poi.util.TempFile; +import org.apache.poi.xssf.XSSFTestDataSamples; import org.junit.jupiter.api.Test; public final class TestXSLFSlideShowFactory extends BaseTestSlideShowFactory { @@ -87,6 +92,27 @@ public final class TestXSLFSlideShowFactory extends BaseTestSlideShowFactory { testFactoryFromProtectedNative(pFile.getAbsolutePath(), password); } + @Test + void testBug65634() throws IOException { + File file = XSSFTestDataSamples.getSampleFile("workbook.xml"); + try (FileInputStream fis = new FileInputStream(file)) { + try { + SlideShow slideShow = SlideShowFactory.create(fis); + if (slideShow != null) slideShow.close(); + fail("SlideShowFactory.create should have failed"); + } catch (IOException ie) { + assertEquals("Can't open slideshow - unsupported file type: XML", ie.getMessage()); + } + } + try { + SlideShow slideShow = SlideShowFactory.create(file); + if (slideShow != null) slideShow.close(); + fail("SlideShowFactory.create should have failed"); + } catch (IOException ie) { + assertEquals("Can't open slideshow - unsupported file type: XML", ie.getMessage()); + } + } + private static File createProtected() throws IOException, GeneralSecurityException { try (POIFSFileSystem fs = new POIFSFileSystem()) { EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShowFactory.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShowFactory.java index d82c659d71..2215f3c0c7 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShowFactory.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShowFactory.java @@ -17,12 +17,43 @@ package org.apache.poi.hslf.usermodel; +import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.sl.usermodel.BaseTestSlideShowFactory; +import org.apache.poi.sl.usermodel.SlideShow; +import org.apache.poi.sl.usermodel.SlideShowFactory; import org.junit.jupiter.api.Test; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + public final class TestHSLFSlideShowFactory extends BaseTestSlideShowFactory { @Test void testFactory() throws Exception { testFactory("pictures.ppt", "Password_Protected-hello.ppt", "hello"); } + + @Test + void testBug65634() throws IOException { + File file = HSSFTestDataSamples.getSampleFile("workbook.xml"); + try (FileInputStream fis = new FileInputStream(file)) { + try { + SlideShow slideShow = SlideShowFactory.create(fis); + if (slideShow != null) slideShow.close(); + fail("SlideShowFactory.create should have failed"); + } catch (IOException ie) { + assertEquals("Can't open slideshow - unsupported file type: XML", ie.getMessage()); + } + } + try { + SlideShow slideShow = SlideShowFactory.create(file); + if (slideShow != null) slideShow.close(); + fail("SlideShowFactory.create should have failed"); + } catch (IOException ie) { + assertEquals("Can't open slideshow - unsupported file type: XML", ie.getMessage()); + } + } }