poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r413658 - in /jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf: HSLFSlideShow.java usermodel/PictureData.java
Date Mon, 12 Jun 2006 14:06:09 GMT
Author: nick
Date: Mon Jun 12 07:06:08 2006
New Revision: 413658

URL: http://svn.apache.org/viewvc?rev=413658&view=rev
Log:
Better handling of zero sized images, and where the picture stream doesn't have enough data
left for a full header

Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java?rev=413658&r1=413657&r2=413658&view=diff
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java Mon Jun 12
07:06:08 2006
@@ -219,7 +219,7 @@
 
 		ArrayList p = new ArrayList();
 		int pos = 0; 
-		while (pos < pictstream.length) {
+		while (pos < (pictstream.length - PictureData.HEADER_SIZE)) {
 			PictureData pict = new PictureData(pictstream, pos);
 			p.add(pict);
 			pos += PictureData.HEADER_SIZE + pict.getSize();

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java?rev=413658&r1=413657&r2=413658&view=diff
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java Mon
Jun 12 07:06:08 2006
@@ -63,9 +63,20 @@
 		header = new byte[PictureData.HEADER_SIZE];
 		System.arraycopy(pictstream, offset, header, 0, header.length);
 
-		int size = LittleEndian.getInt(header, 4) - 17;
+		// Get the size of the picture, and make sure it's sane
+		// Size is stored unsigned, since it must always be positive
+		int size = (int)LittleEndian.getUInt(header, 4) - 17;
+		int startPos = offset + PictureData.HEADER_SIZE;
+		if(size < 0) { size = 0; }
+		if(size > (pictstream.length - startPos)) { 
+			int remaining = pictstream.length - startPos;
+			System.err.println("Warning: PictureData claimed picture was of length " + size + ", but
only " + remaining + " remained!");
+			size = remaining;
+		}
+
+		// Save the picture data
 		pictdata = new byte[size];
-		System.arraycopy(pictstream, offset + PictureData.HEADER_SIZE, pictdata, 0, pictdata.length);
+		System.arraycopy(pictstream, startPos, pictdata, 0, pictdata.length);
 	}
 
 	/**



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message