From 1559a6d4bd75f699e370a9593c033a3ff6113309 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 7 Sep 2009 04:55:32 +0000 Subject: [PATCH] Do not allow text longer than 32,767 characters in HSSF cells, see Bugzilla 47751 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@811994 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/usermodel/HSSFCell.java | 5 +++ .../org/apache/poi/ss/SpreadsheetVersion.java | 21 +++++++++--- .../apache/poi/hssf/usermodel/TestBugs.java | 17 +++++++++- .../poi/hssf/usermodel/TestHSSFCell.java | 32 ++++++++++++++++++ .../ss/usermodel/BaseTestBugzillaIssues.java | 32 ------------------ test-data/spreadsheet/46368.xls | Bin 0 -> 73216 bytes 6 files changed, 70 insertions(+), 37 deletions(-) create mode 100755 test-data/spreadsheet/46368.xls diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 29a46c5d34..999fa287dc 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -540,6 +540,11 @@ public class HSSFCell implements Cell { setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex); return; } + + if(hvalue.length() > SpreadsheetVersion.EXCEL97.getMaxTextLength()){ + throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters"); + } + if (_cellType == CELL_TYPE_FORMULA) { // Set the 'pre-evaluated result' for the formula // note - formulas do not preserve text formatting. diff --git a/src/java/org/apache/poi/ss/SpreadsheetVersion.java b/src/java/org/apache/poi/ss/SpreadsheetVersion.java index 316e5af06f..d4edaec53f 100755 --- a/src/java/org/apache/poi/ss/SpreadsheetVersion.java +++ b/src/java/org/apache/poi/ss/SpreadsheetVersion.java @@ -36,9 +36,11 @@ public enum SpreadsheetVersion { *
  • The total number of available rows is 64k (2^16)
  • *
  • The maximum number of arguments to a function is 30
  • *
  • Number of conditional format conditions on a cell is 3
  • + *
  • Length of text cell contents is unlimited
  • + *
  • Length of text cell contents is 32767
  • * */ - EXCEL97(0x10000, 0x0100, 30, 3), + EXCEL97(0x10000, 0x0100, 30, 3, 32767), /** * Excel2007 @@ -49,21 +51,24 @@ public enum SpreadsheetVersion { *
  • The maximum number of arguments to a function is 255
  • *
  • Number of conditional format conditions on a cell is unlimited * (actually limited by available memory in Excel)
  • + *
  • Length of text cell contents is unlimited
  • *