[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
This commit is contained in:
PJ Fanning 2022-07-01 16:30:15 +00:00
parent 86cc8d1b4b
commit b4c92e4ae5
2 changed files with 57 additions and 0 deletions

View File

@ -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);

View File

@ -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());
}
}
}