From 8c18d93a6622fb258bfa562e4934e65b066e67c9 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 13 Jan 2019 17:14:31 +0000 Subject: [PATCH] Don't fail on row-nums larger than Integer.MAX_VALUE, we had one sample file which triggered this git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1851211 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/util/CellReference.java | 7 +++++-- .../org/apache/poi/ss/util/TestCellReference.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/poi/ss/util/CellReference.java b/src/java/org/apache/poi/ss/util/CellReference.java index be2737a1c1..067cdeb512 100644 --- a/src/java/org/apache/poi/ss/util/CellReference.java +++ b/src/java/org/apache/poi/ss/util/CellReference.java @@ -350,8 +350,11 @@ public class CellReference { * @throws NumberFormatException if rowStr is not parseable as an integer */ public static boolean isRowWithinRange(String rowStr, SpreadsheetVersion ssVersion) { - final int rowNum = Integer.parseInt(rowStr) - 1; - return isRowWithinRange(rowNum, ssVersion); + final long rowNum = Long.parseLong(rowStr) - 1; + if(rowNum > Integer.MAX_VALUE) { + return false; + } + return isRowWithinRange((int)rowNum, ssVersion); } /** diff --git a/src/testcases/org/apache/poi/ss/util/TestCellReference.java b/src/testcases/org/apache/poi/ss/util/TestCellReference.java index c2f7dfa87a..686f2b40ce 100644 --- a/src/testcases/org/apache/poi/ss/util/TestCellReference.java +++ b/src/testcases/org/apache/poi/ss/util/TestCellReference.java @@ -399,10 +399,10 @@ public final class TestCellReference { assertFalse("1 beyond last row", CellReference.isRowWithinRange(1048576, ss)); } - @Test(expected=NumberFormatException.class) + @Test public void isRowWithinRangeNonInteger_BigNumber() { String rowNum = "4000000000"; - CellReference.isRowWithinRange(rowNum, SpreadsheetVersion.EXCEL2007); + assertFalse(CellReference.isRowWithinRange(rowNum, SpreadsheetVersion.EXCEL2007)); } @Test(expected=NumberFormatException.class) -- 2.39.5