]> source.dussan.org Git - poi.git/commitdiff
Bug 47261 - SlideShow.removeSlide makes PPT corrupted
authorAndreas Beeker <kiwiwings@apache.org>
Tue, 30 Dec 2014 01:05:41 +0000 (01:05 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Tue, 30 Dec 2014 01:05:41 +0000 (01:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1648458 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/record/Document.java
src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
test-data/slideshow/bug47261.ppt [new file with mode: 0644]

index a9510ae55a6c8b921da736b271abf76ec668e837..2cfafa8d2e2746bdf8ae1a1395b714abf2ec7c63 100644 (file)
@@ -175,6 +175,10 @@ public final class Document extends PositionDependentRecordContainer
                // The new SlideListWithText should go in
                //  just before the EndDocumentRecord
                Record endDoc = _children[_children.length - 1];
+               if(endDoc.getRecordType() == RecordTypes.RoundTripCustomTableStyles12Atom.typeID) {
+                   // last record can optionally be a RoundTripCustomTableStyles12Atom
+                   endDoc = _children[_children.length - 2];
+               }
                if(endDoc.getRecordType() != RecordTypes.EndDocument.typeID) {
                        throw new IllegalStateException("The last child record of a Document should be EndDocument, but it was " + endDoc);
                }
index fca49bacedd16f203d0e0c196927f06e44517726..3d99e0a716ca24e7e47c2add4f6d463d85b87a35 100644 (file)
@@ -67,6 +67,7 @@ public final class RecordTypes {
     public static final Type NamedShow = new Type(1041,null);
     public static final Type NamedShowSlides = new Type(1042,null);
     public static final Type SheetProperties = new Type(1044,null);
+    public static final Type RoundTripCustomTableStyles12Atom = new Type(1064,null);
     public static final Type List = new Type(2000,null);
     public static final Type FontCollection = new Type(2005,FontCollection.class);
     public static final Type BookmarkCollection = new Type(2019,null);
index 6b26c28d7db644bc40e5f751fa2ce6b92b3ce6c8..6e7663d269737251980e8b6dd40ea5c653f56828 100644 (file)
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -595,4 +596,18 @@ public final class TestBugs {
             inputStream.close();
         }
     }
+    
+    @Test
+    public void bug47261() throws Exception {
+        InputStream inputStream = new FileInputStream(_slTests.getFile("bug47261.ppt"));
+        try {
+            SlideShow slideShow = new SlideShow(inputStream);
+            slideShow.removeSlide(0);
+            slideShow.createSlide();
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            slideShow.write(bos);
+        } finally {
+            inputStream.close();
+        }
+    }
 }
diff --git a/test-data/slideshow/bug47261.ppt b/test-data/slideshow/bug47261.ppt
new file mode 100644 (file)
index 0000000..cece730
Binary files /dev/null and b/test-data/slideshow/bug47261.ppt differ