Author: nick
Date: Mon Feb  4 12:52:12 2013
New Revision: 1442095

URL: http://svn.apache.org/viewvc?rev=1442095&view=rev
Log:
An XBAT may not be fully used, and remaining entries may be 0 not 
POIFSConstants.UNUSED_BLOCK, so avoid trying to process any that we know aren't 
used. Fixes bug #53810

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java

Modified: 
poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java?rev=1442095&r1=1442094&r2=1442095&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java 
Mon Feb  4 12:52:12 2013
@@ -356,6 +356,9 @@ public class NPOIFSFileSystem extends Bl
           readBAT(fatAt, loopDetector);
        }
        
+       // Work out how many FAT blocks remain in the XFATs
+       int remainingFATs = _header.getBATCount() - 
_header.getBATArray().length;
+       
        // Now read the XFAT blocks, and the FATs within them
        BATBlock xfat; 
        int nextAt = _header.getXBATIndex();
@@ -367,11 +370,14 @@ public class NPOIFSFileSystem extends Bl
           nextAt = xfat.getValueAt(bigBlockSize.getXBATEntriesPerBlock());
           _xbat_blocks.add(xfat);
           
-          for(int j=0; j<bigBlockSize.getXBATEntriesPerBlock(); j++) {
+          // Process all the (used) FATs from this XFAT
+          int xbatFATs = Math.min(remainingFATs, 
bigBlockSize.getXBATEntriesPerBlock());
+          for(int j=0; j<xbatFATs; j++) {
              int fatAt = xfat.getValueAt(j);
              if(fatAt == POIFSConstants.UNUSED_BLOCK || fatAt == 
POIFSConstants.END_OF_CHAIN) break;
              readBAT(fatAt, loopDetector);
           }
+          remainingFATs -= xbatFATs;
        }
        
        // We're now able to load steams



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to