You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2009/08/20 15:49:33 UTC

svn commit: r806172 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/ java/org/apache/poi/hpsf/ java/org/apache/poi/hpsf/extractor/ scratchpad/src/org/apache/poi/hdgf/ scratchpad/src/org/apache/poi/hslf/ scratchpad/src/org/apache/p...

Author: yegor
Date: Thu Aug 20 13:49:33 2009
New Revision: 806172

URL: http://svn.apache.org/viewvc?rev=806172&view=rev
Log:
Avoid exception when reading ClipboardData packet in OLE property sets, see bugzilla 45583

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/data/42726.xls   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/POIDocument.java
    poi/trunk/src/java/org/apache/poi/hpsf/Section.java
    poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java
    poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Aug 20 13:49:33 2009
@@ -33,7 +33,7 @@
 
     <changes>
         <release version="3.5-beta7" date="2009-??-??">
-           <action dev="POI-DEVELOPERS" type="add">47668 - Improved parsing of OOXML documents</action>
+           <action dev="POI-DEVELOPERS" type="add">45583 - Avoid exception when reading ClipboardData packet in OLE property sets</action>
            <action dev="POI-DEVELOPERS" type="add">47652 - Added support for reading encrypted workbooks</action>
            <action dev="POI-DEVELOPERS" type="add">47604 - Implementation of an XML to XLSX Importer using Custom XML Mapping</action>
            <action dev="POI-DEVELOPERS" type="fix">47620 - Avoid FormulaParseException in XSSFWorkbook.setRepeatingRowsAndColumns when removing repeated rows and columns</action>

Modified: poi/trunk/src/java/org/apache/poi/POIDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIDocument.java?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIDocument.java Thu Aug 20 13:49:33 2009
@@ -47,19 +47,19 @@
  */
 public abstract class POIDocument {
 	/** Holds metadata on our document */
-	protected SummaryInformation sInf;
+	private SummaryInformation sInf;
 	/** Holds further metadata on our document */
-	protected DocumentSummaryInformation dsInf;
+	private DocumentSummaryInformation dsInf;
 	/** The open POIFS FileSystem that contains our document */
 	protected POIFSFileSystem filesystem;
 	/**	The directory that our document lives in */
 	protected DirectoryNode directory;
 	
 	/** For our own logging use */
-	protected POILogger logger = POILogFactory.getLogger(this.getClass());
+	private final static POILogger logger = POILogFactory.getLogger(POIDocument.class);
 
     /* Have the property streams been read yet? (Only done on-demand) */
-    protected boolean initialized = false;
+    private boolean initialized = false;
     
 
     protected POIDocument(DirectoryNode dir, POIFSFileSystem fs) {
@@ -120,7 +120,10 @@
 	 *  if it wasn't found
 	 */
 	protected PropertySet getPropertySet(String setName) {
-		DocumentInputStream dis;
+        //directory can be null when creating new documents
+        if(directory == null) return null;
+        
+        DocumentInputStream dis;
 		try {
 			// Find the entry, and get an input stream for it
 			dis = directory.createDocumentInputStream(setName);
@@ -157,14 +160,16 @@
 	 * @param writtenEntries a list of POIFS entries to add the property names too
 	 */
 	protected void writeProperties(POIFSFileSystem outFS, List writtenEntries) throws IOException {
-        if(sInf != null) {
-			writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME,sInf,outFS);
+        SummaryInformation si = getSummaryInformation();
+        if(si != null) {
+			writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME, si, outFS);
 			if(writtenEntries != null) {
 				writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME);
 			}
 		}
-		if(dsInf != null) {
-			writePropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME,dsInf,outFS);
+        DocumentSummaryInformation dsi = getDocumentSummaryInformation();
+        if(dsi != null) {
+			writePropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME, dsi, outFS);
 			if(writtenEntries != null) {
 				writtenEntries.add(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
 			}

Modified: poi/trunk/src/java/org/apache/poi/hpsf/Section.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/Section.java?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/Section.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/Section.java Thu Aug 20 13:49:33 2009
@@ -240,16 +240,6 @@
         {
             ple = propertyList.get(propertyCount - 1);
             ple.length = size - ple.offset;
-            if (ple.length <= 0)
-            {
-                final StringBuffer b = new StringBuffer();
-                b.append("The property set claims to have a size of ");
-                b.append(size);
-                b.append(" bytes. However, it exceeds ");
-                b.append(ple.offset);
-                b.append(" bytes.");
-                throw new IllegalPropertySetDataException(b.toString());
-            }
         }
 
         /* Look for the codepage. */

Modified: poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java Thu Aug 20 13:49:33 2009
@@ -272,9 +272,20 @@
             }
             case Variant.VT_CF:
             {
+                if(l1 < 0) {
+                    /**
+                     *  YK: reading the ClipboardData packet (VT_CF) is not quite correct.
+                     *  The size of the data is determined by the first four bytes of the packet
+                     *  while the current implementation calculates it in the Section constructor.
+                     *  Test files in Bugzilla 42726 and 45583 clearly show that this approach does not always work.
+                     *  The workaround below attempts to gracefully handle such cases instead of throwing exceptions.
+                     * 
+                     *  August 20, 2009
+                     */
+                    l1 = LittleEndian.getInt(src, o1); o1 += LittleEndian.INT_SIZE;
+                }
                 final byte[] v = new byte[l1];
-                for (int i = 0; i < l1; i++)
-                    v[i] = src[(o1 + i)];
+                System.arraycopy(src, o1, v, 0, v.length);
                 value = v;
                 break;
             }
@@ -509,7 +520,7 @@
             }
             case Variant.VT_CF:
             {
-                final byte[] b = (byte[]) value; 
+                final byte[] b = (byte[]) value;
                 out.write(b);
                 length = b.length;
                 break;

Modified: poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java Thu Aug 20 13:49:33 2009
@@ -55,7 +55,7 @@
 		text.append( getPropertiesText(dsi) );
 
 		// Now custom ones
-		CustomProperties cps = dsi.getCustomProperties();
+		CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
 		if(cps != null) {
 			Iterator keys = cps.keySet().iterator();
 			while(keys.hasNext()) {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java Thu Aug 20 13:49:33 2009
@@ -68,9 +68,6 @@
 		_docstream = new byte[docProps.getSize()];
 		dir.createDocumentInputStream("VisioDocument").read(_docstream);
 
-		// Read in the common POI streams
-		readProperties();
-
 		// Check it's really visio
 		String typeString = new String(_docstream, 0, 20);
 		if(! typeString.equals(VISIO_HEADER)) {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java Thu Aug 20 13:49:33 2009
@@ -146,9 +146,6 @@
 		// Now, build records based on the PowerPoint stream
 		buildRecords();
 
-		// Look for Property Streams:
-		readProperties();
-
 		// Look for any other streams
 		readOtherStreams();
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Thu Aug 20 13:49:33 2009
@@ -170,7 +170,6 @@
   {
     // Sort out the hpsf properties
 	super(directory, pfilesystem);
-    readProperties();
 
     // read in the main stream.
     DocumentEntry documentProps = (DocumentEntry)

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java?rev=806172&r1=806171&r2=806172&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java Thu Aug 20 13:49:33 2009
@@ -25,6 +25,7 @@
 
 import org.apache.poi.hssf.extractor.ExcelExtractor;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
 public final class TestHPSFPropertiesExtractor extends TestCase {
@@ -117,4 +118,13 @@
 		assertTrue(fsText.indexOf("AUTHOR = marshall") > -1);
 		assertTrue(fsText.indexOf("TITLE = Titel: \u00c4h") > -1);
 	}
+
+    public void test42726() throws Exception {
+        HPSFPropertiesExtractor ex = new HPSFPropertiesExtractor(HSSFTestDataSamples.openSampleWorkbook("42726.xls"));
+        String txt = ex.getText();
+        assertTrue(txt.indexOf("PID_AUTHOR") != -1);
+        assertTrue(txt.indexOf("PID_EDITTIME") != -1);
+        assertTrue(txt.indexOf("PID_REVNUMBER") != -1);
+        assertTrue(txt.indexOf("PID_THUMBNAIL") != -1);
+    }
 }

Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/42726.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/42726.xls?rev=806172&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/42726.xls
------------------------------------------------------------------------------
    svn:executable = *

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/42726.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org