From: Dominik Stadler Date: Wed, 19 Aug 2015 13:36:08 +0000 (+0000) Subject: POI Bug 58260: Fix checks for limit on number of styles in XSSF/SXSSF and fix having... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c275dea88c13d5a219c84dfab101dc6e5e126418;p=poi.git POI Bug 58260: Fix checks for limit on number of styles in XSSF/SXSSF and fix having more than 32k styles in SXSSF workbooks git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1696586 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java index c891509274..a119e457e4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java @@ -563,11 +563,12 @@ public class StylesTable extends POIXMLDocumentPart { } public XSSFCellStyle createCellStyle() { - int xfSize = styleXfs.size(); - if (xfSize > MAXIMUM_STYLE_ID) + if (getNumCellStyles() > MAXIMUM_STYLE_ID) { throw new IllegalStateException("The maximum number of Cell Styles was exceeded. " + "You can define up to " + MAXIMUM_STYLE_ID + " style in a .xlsx Workbook"); + } + int xfSize = styleXfs.size(); CTXf xf = CTXf.Factory.newInstance(); xf.setNumFmtId(0); xf.setFontId(0); diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java index fe72146617..fbcb6b103d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java @@ -189,7 +189,12 @@ public class SheetDataWriter { String ref = new CellReference(_rownum, columnIndex).formatAsString(); _out.write(" 32767 + // we should really change the API to be "int" for getIndex() but + // that needs API changes + assertEquals(i+1, style.getIndex() & 0xffff); + } + + //Create cell + Cell cell = row.createCell(0); + + //Set cell style + cell.setCellStyle(style); + + //Set cell value + cell.setCellValue("r" + rnd.nextInt()); + } + + // should fail if we try to add more now + try { + wb.createCellStyle(); + fail("Should fail after " + maxStyles + " styles, but did not fail"); + } catch (IllegalStateException e) { + // expected here + } + + /*//add column width for appearance sake + worksheet.setColumnWidth(0, 5000); + + // Write the output to a file + System.out.println("Writing..."); + OutputStream fileOut = new FileOutputStream("C:\\temp\\58260." + _testDataProvider.getStandardFileNameExtension()); + + // the resulting file can be compressed nicely, so we need to disable the zip bomb detection here + double before = ZipSecureFile.getMinInflateRatio(); + try { + ZipSecureFile.setMinInflateRatio(0.00001); + wb.write(fileOut); + } finally { + fileOut.close(); + ZipSecureFile.setMinInflateRatio(before); + }*/ + + wb.close(); + } }