diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java index a9510ae55..2cfafa8d2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java @@ -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); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java index fca49bace..3d99e0a71 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java @@ -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); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java index 6b26c28d7..6e7663d26 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java @@ -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 index 000000000..cece730aa Binary files /dev/null and b/test-data/slideshow/bug47261.ppt differ