Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #519 Prevent infinite loop when getting references from invalid range #521

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Extract range validation to method
  • Loading branch information
rdarcy1 committed Jun 3, 2018
commit c1fcee3884fe3fc323232b2bd2ab7cbc43c17bdb
23 changes: 20 additions & 3 deletions src/PhpSpreadsheet/Cell/Coordinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,7 @@ protected static function getReferencesForCellBlock($cellBlock)
$currentCol = $startCol;
$currentRow = $startRow;

if ($startCol >= $endCol || $currentRow > $endRow) {
throw new Exception('Invalid range: "' . $cellBlock . '"');
}
static::validateRange($cellBlock, $startCol, $endCol, $currentRow, $endRow);

// Loop cells
while ($currentCol < $endCol) {
Expand Down Expand Up @@ -520,4 +518,23 @@ protected static function getCellBlocksFromRangeString($pRange)
{
return explode(' ', str_replace('$', '', strtoupper($pRange)));
}

/**
* Check that the given range is valid, i.e. that the start column and row are not greater than the end column and
* row.
*
* @param string $cellBlock The original range, for displaying a meaningful error message
* @param string $startCol
* @param string $endCol
* @param int $currentRow
* @param int $endRow
*
* @throws Exception
*/
protected static function validateRange($cellBlock, $startCol, $endCol, $currentRow, $endRow)
{
if ($startCol >= $endCol || $currentRow > $endRow) {
throw new Exception('Invalid range: "' . $cellBlock . '"');
}
}
}