]> source.dussan.org Git - poi.git/commitdiff
An XBAT may not be fully used, and remaining entries may be 0 not POIFSConstants...
authorNick Burch <nick@apache.org>
Mon, 4 Feb 2013 12:52:12 +0000 (12:52 +0000)
committerNick Burch <nick@apache.org>
Mon, 4 Feb 2013 12:52:12 +0000 (12:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1442095 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java

index def2af198df364757b2e40b250a52e6a615cad14..d2e399794b7409d2d2b01ab972fedca81626deb9 100644 (file)
@@ -356,6 +356,9 @@ public class NPOIFSFileSystem extends BlockStore
           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 BlockStore
           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