]> source.dussan.org Git - poi.git/commitdiff
#58718 - Master styles not initialized when running multithreaded
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 13 Dec 2015 01:50:24 +0000 (01:50 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 13 Dec 2015 01:50:24 +0000 (01:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1719758 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TabStopPropCollection.java
src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextProp.java
src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java
src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
test-data/slideshow/bug58718_008495.ppt [new file with mode: 0644]
test-data/slideshow/bug58718_008524.ppt [new file with mode: 0644]
test-data/slideshow/bug58718_008558.ppt [new file with mode: 0644]
test-data/slideshow/bug58718_349008.ppt [new file with mode: 0644]

index 366886217006f1073822daef776e2adb9d434202..d1046a1f042a0c2eca9609f7b91dd584b4ac7ee2 100644 (file)
@@ -93,13 +93,13 @@ public class TabStopPropCollection extends TextProp {
      */\r
     public void parseProperty(byte data[], int offset) {\r
         int count = LittleEndian.getUShort(data, offset);\r
-        offset += LittleEndianConsts.SHORT_SIZE;\r
+        int off = offset + LittleEndianConsts.SHORT_SIZE;\r
         for (int i=0; i<count; i++) {\r
-            int position = LittleEndian.getShort(data, offset);\r
-            offset += LittleEndianConsts.SHORT_SIZE;\r
-            int recVal = LittleEndian.getShort(data, offset);\r
+            int position = LittleEndian.getShort(data, off);\r
+            off += LittleEndianConsts.SHORT_SIZE;\r
+            int recVal = LittleEndian.getShort(data, off);\r
             TabStopType type = TabStopType.fromRecordVal(recVal);\r
-            offset += LittleEndianConsts.SHORT_SIZE;\r
+            off += LittleEndianConsts.SHORT_SIZE;\r
             tabStops.add(new TabStop(position, type));\r
             \r
         }\r
@@ -109,4 +109,15 @@ public class TabStopPropCollection extends TextProp {
     public int getSize() {\r
         return LittleEndianConsts.SHORT_SIZE + tabStops.size()*LittleEndianConsts.INT_SIZE;\r
     }\r
+    \r
+    @Override\r
+    public TabStopPropCollection clone() {\r
+        TabStopPropCollection other = (TabStopPropCollection)super.clone();\r
+        other.tabStops = new ArrayList<TabStop>();\r
+        for (TabStop ts : tabStops) {\r
+            TabStop tso = new TabStop(ts.getPosition(), ts.getType());\r
+            other.tabStops.add(tso);\r
+        }\r
+        return other;\r
+    }\r
 }\r
index 07d663b4a99924a6b5f1da9a39937f81dceb448a..e95cdfd29c49e3e1f9394c358e3588321bca40e8 100644 (file)
@@ -98,6 +98,7 @@ public class TextProp implements Cloneable {
                }
        }
        
+       @Override
        public int hashCode() {
         final int prime = 31;
         int result = 1;
@@ -108,6 +109,7 @@ public class TextProp implements Cloneable {
         return result;
     }
 
+       @Override
     public boolean equals(Object obj) {
         if (this == obj) return true;
         if (obj == null) return false;
@@ -121,4 +123,15 @@ public class TextProp implements Cloneable {
         if (sizeOfDataBlock != other.sizeOfDataBlock) return false;
         return true;
     }
+    
+    @Override
+    public String toString() {
+        int len;
+        switch (sizeOfDataBlock) {
+        case 1: len = 4; break;
+        case 2: len = 6; break;
+        default: len = 10; break;
+        }
+        return String.format("%s = %d (%0#"+len+"X mask / %d bytes)", propName, dataValue, maskInHeader, sizeOfDataBlock);
+    }
 }
\ No newline at end of file
index 09415a01c3a06ca480fa5aedc7d41f0568372137..cf45cc790f861916e7bfe4c64fecddf0103af1b3 100644 (file)
@@ -214,13 +214,11 @@ public class TextPropCollection {
                                // Bingo, data contains this property
                                TextProp prop = tp.clone();
                                int val = 0;
-                               if (prop instanceof TabStopPropCollection) {
-                                   ((TabStopPropCollection)prop).parseProperty(data, dataOffset+bytesPassed);
-                               } else if (prop.getSize() == 2) {
+                               if (prop.getSize() == 2) {
                                        val = LittleEndian.getShort(data,dataOffset+bytesPassed);
                                } else if(prop.getSize() == 4) {
                                        val = LittleEndian.getInt(data,dataOffset+bytesPassed);
-                               } else if (prop.getSize() == 0) {
+                               } else if (prop.getSize() == 0 && !(prop instanceof TabStopPropCollection)) {
                     //remember "special" bits.
                     maskSpecial |= tp.getMask();
                     continue;
@@ -228,6 +226,8 @@ public class TextPropCollection {
                                
                                if (prop instanceof BitMaskTextProp) {
                                    ((BitMaskTextProp)prop).setValueWithMask(val, containsField);
+                               } else if (prop instanceof TabStopPropCollection) {
+                                   ((TabStopPropCollection)prop).parseProperty(data, dataOffset+bytesPassed);
                                } else {
                                    prop.setValue(val);
                                }
index 2d9541e1bdec9ca81121a6879451dd859687b647..6d1c4873d7e4e88ca473e69fa2e4400792186f28 100644 (file)
@@ -144,7 +144,7 @@ public final class TxMasterStyleAtom extends RecordAtom {
         charStyles = new ArrayList<TextPropCollection>(levels);
 
         for(short i = 0; i < levels; i++) {
-            TextPropCollection prprops = new TextPropCollection(0, TextPropType.paragraph); //  getParagraphProps(type, j)
+            TextPropCollection prprops = new TextPropCollection(0, TextPropType.paragraph);
             if (type >= TextHeaderAtom.CENTRE_BODY_TYPE) {
                 // Fetch the 2 byte value, that is safe to ignore for some types of text
                 short indentLevel = LittleEndian.getShort(_data, pos);
@@ -162,7 +162,7 @@ public final class TxMasterStyleAtom extends RecordAtom {
 
             head = LittleEndian.getInt(_data, pos);
             pos += LittleEndian.INT_SIZE;
-            TextPropCollection chprops = new TextPropCollection(0, TextPropType.character); //  getCharacterProps(type, j)
+            TextPropCollection chprops = new TextPropCollection(0, TextPropType.character);
             pos += chprops.buildTextPropList( head, _data, pos);
             charStyles.add(chprops);
         }
index 067f6ca916c43d298050a06b476758413f28e783..6e11a41b54cb1fecb2127c07d8b23a6a3cbdb0e5 100644 (file)
@@ -39,6 +39,7 @@ import org.apache.poi.ddf.EscherColorRef;
 import org.apache.poi.ddf.EscherProperties;
 import org.apache.poi.hslf.HSLFTestDataSamples;
 import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
+import org.apache.poi.hslf.extractor.PowerPointExtractor;
 import org.apache.poi.hslf.model.HeadersFooters;
 import org.apache.poi.hslf.record.Document;
 import org.apache.poi.hslf.record.Record;
@@ -756,6 +757,17 @@ public final class TestBugs {
         assertEquals("foobaa", tr.getRawText());
         ppt2.close();
     }
+
+    @Test
+    public void bug58718() throws IOException {
+        String files[] = { "bug58718_008524.ppt","bug58718_008558.ppt","bug58718_349008.ppt","bug58718_008495.ppt",  }; 
+        for (String f : files) {
+            File sample = HSLFTestDataSamples.getSampleFile(f);
+            PowerPointExtractor ex = new PowerPointExtractor(sample.getAbsolutePath());
+            assertNotNull(ex.getText());
+            ex.close();
+        }
+    }
     
     private static HSLFSlideShow open(String fileName) throws IOException {
         File sample = HSLFTestDataSamples.getSampleFile(fileName);
diff --git a/test-data/slideshow/bug58718_008495.ppt b/test-data/slideshow/bug58718_008495.ppt
new file mode 100644 (file)
index 0000000..9d9009a
Binary files /dev/null and b/test-data/slideshow/bug58718_008495.ppt differ
diff --git a/test-data/slideshow/bug58718_008524.ppt b/test-data/slideshow/bug58718_008524.ppt
new file mode 100644 (file)
index 0000000..96eddb7
Binary files /dev/null and b/test-data/slideshow/bug58718_008524.ppt differ
diff --git a/test-data/slideshow/bug58718_008558.ppt b/test-data/slideshow/bug58718_008558.ppt
new file mode 100644 (file)
index 0000000..c8a6d52
Binary files /dev/null and b/test-data/slideshow/bug58718_008558.ppt differ
diff --git a/test-data/slideshow/bug58718_349008.ppt b/test-data/slideshow/bug58718_349008.ppt
new file mode 100644 (file)
index 0000000..41d9759
Binary files /dev/null and b/test-data/slideshow/bug58718_349008.ppt differ