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

Prevent index out of array bounds exception #6

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Changes from all commits
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
19 changes: 8 additions & 11 deletions EPPlus/CellStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using OfficeOpenXml;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;

internal class IndexBase : IComparable<IndexBase>
{
Expand All @@ -53,7 +50,7 @@ internal int IndexPointer
get;
set;
}
internal short Index;
internal int Index;
public int CompareTo(IndexItem other)
{
return Index - other.Index;
Expand Down Expand Up @@ -653,7 +650,7 @@ internal void SetValue(int Row, int Column, T Value)
pageItem = _columnIndex[col]._pages[pos];
}

short ix = (short)(Row - ((pageItem.Index << pageBits) + pageItem.Offset));
int ix = Row - ((pageItem.Index << pageBits) + pageItem.Offset);
_searchItem.Index = ix;
var cellPos = Array.BinarySearch(pageItem.Rows, 0, pageItem.RowCount, _searchItem);
if (cellPos < 0)
Expand All @@ -671,7 +668,7 @@ internal void SetValue(int Row, int Column, T Value)
col = ~col;
AddColumn(col, Column);
AddPage(_columnIndex[col], 0, page);
short ix = (short)(Row - (page << pageBits));
int ix = Row - (page << pageBits);
AddCell(_columnIndex[col], 0, 0, ix, Value);
}
}
Expand Down Expand Up @@ -742,7 +739,7 @@ internal void SetRangeValueSpecial(int fromRow, int fromColumn, int toRow, int t
pageItem = _columnIndex[col]._pages[pos];
}

short ix = (short)(rowIx - ((pageItem.Index << pageBits) + pageItem.Offset));
int ix = rowIx - ((pageItem.Index << pageBits) + pageItem.Offset);
_searchItem.Index = ix;
var cellPos = Array.BinarySearch(pageItem.Rows, 0, pageItem.RowCount, _searchItem);
if (cellPos < 0)
Expand All @@ -761,7 +758,7 @@ internal void SetRangeValueSpecial(int fromRow, int fromColumn, int toRow, int t
col = ~col;
AddColumn(col, colIx);
AddPage(_columnIndex[col], 0, page);
short ix = (short)(rowIx - (page << pageBits));
int ix = rowIx - (page << pageBits);
AddCell(_columnIndex[col], 0, 0, ix, default(T));
Updater(_values, _columnIndex[col]._pages[0].Rows[0].IndexPointer, rowIx, colIx, Value);
}
Expand Down Expand Up @@ -812,7 +809,7 @@ internal void SetValueSpecial(int Row, int Column, SetValueDelegate Updater, obj
pageItem = _columnIndex[col]._pages[pos];
}

short ix = (short)(Row - ((pageItem.Index << pageBits) + pageItem.Offset));
int ix = Row - ((pageItem.Index << pageBits) + pageItem.Offset);
_searchItem.Index = ix;
var cellPos = Array.BinarySearch(pageItem.Rows, 0, pageItem.RowCount, _searchItem);
if (cellPos < 0)
Expand All @@ -831,7 +828,7 @@ internal void SetValueSpecial(int Row, int Column, SetValueDelegate Updater, obj
col = ~col;
AddColumn(col, Column);
AddPage(_columnIndex[col], 0, page);
short ix = (short)(Row - (page << pageBits));
int ix = Row - (page << pageBits);
AddCell(_columnIndex[col], 0, 0, ix, default(T));
Updater(_values, _columnIndex[col]._pages[0].Rows[0].IndexPointer, Value);
}
Expand Down Expand Up @@ -1421,7 +1418,7 @@ internal static int GetSize(int size)
}
return newSize;
}
private void AddCell(ColumnIndex columnIndex, int pagePos, int pos, short ix, T value)
private void AddCell(ColumnIndex columnIndex, int pagePos, int pos, int ix, T value)
{
PageIndex pageItem = columnIndex._pages[pagePos];
if (pageItem.RowCount == pageItem.Rows.Length)
Expand Down