]> source.dussan.org Git - poi.git/commitdiff
Fix bug #52446 - Handle files which have been truncated by a few bytes in NPropertyTable
authorNick Burch <nick@apache.org>
Wed, 11 Jan 2012 11:46:41 +0000 (11:46 +0000)
committerNick Burch <nick@apache.org>
Wed, 11 Jan 2012 11:46:41 +0000 (11:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1229963 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/poifs/property/NPropertyTable.java

index 45adb130d601e005fb5c165c8193f6bb0eb1b3c6..139408242dcfe2aa34ba7475aecbe1064a161911 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="fix">52446 - Handle files which have been truncated by a few bytes in NPropertyTable</action>
            <action dev="poi-developers" type="fix">52438 - Update CellDateFormatter to handle times without seconds</action>
            <action dev="poi-developers" type="add">52389 - Support ?/? as well as #/# fractions, and tighten DataFormatter rules for fraction matching</action>
            <action dev="poi-developers" type="add">52200 - Updated XWPF table example code </action>
index f1d470eb48d0c48513808fadd324e5647e49ef51..4f3a1968e62a23070495d267dc9db13c48757c34 100644 (file)
@@ -29,6 +29,8 @@ import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.NPOIFSStream;
 import org.apache.poi.poifs.storage.HeaderBlock;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 /**
  * This class embodies the Property Table for a {@link NPOIFSFileSystem}; 
@@ -36,6 +38,8 @@ import org.apache.poi.poifs.storage.HeaderBlock;
  * filesystem.
  */
 public final class NPropertyTable extends PropertyTableBase {
+    private static final POILogger _logger =
+       POILogFactory.getLogger(NPropertyTable.class);
     private POIFSBigBlockSize _bigBigBlockSize;
 
     public NPropertyTable(HeaderBlock headerBlock)
@@ -90,7 +94,18 @@ public final class NPropertyTable extends PropertyTableBase {
              data = bb.array();
           } else {
              data = new byte[bigBlockSize.getBigBlockSize()];
-             bb.get(data, 0, data.length);
+             
+             int toRead = data.length;
+             if (bb.remaining() < bigBlockSize.getBigBlockSize()) {
+                // Looks to be a truncated block
+                // This isn't allowed, but some third party created files
+                //  sometimes do this, and we can normally read anyway
+                _logger.log(POILogger.WARN, "Short Property Block, ", bb.remaining(),
+                            " bytes instead of the expected " + bigBlockSize.getBigBlockSize());
+                toRead = bb.remaining();
+             }
+             
+             bb.get(data, 0, toRead);
           }
           
           PropertyFactory.convertToProperties(data, properties);