Skip to content

Commit

Permalink
Guard against too many rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvo Isaja committed Jul 23, 2022
1 parent fb0b519 commit b06f026
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/LargeXlsx/Worksheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class Worksheet : IDisposable
{
private const int MinSheetProtectionPasswordLength = 1;
private const int MaxSheetProtectionPasswordLength = 255;
private const int MaxRowNumbers = 1048576;
private readonly Stream _stream;
private readonly StreamWriter _streamWriter;
private readonly Stylesheet _stylesheet;
Expand Down Expand Up @@ -93,6 +94,8 @@ public void Dispose()
public void BeginRow(double? height, bool hidden, XlsxStyle style)
{
CloseLastRow();
if (CurrentRowNumber == MaxRowNumbers)
throw new InvalidOperationException($"A worksheet can contain at most {MaxRowNumbers} rows ({CurrentRowNumber + 1} attempted)");
CurrentRowNumber++;
CurrentColumnNumber = 1;
_streamWriter.Write("<row r=\"{0}\"", CurrentRowNumber);
Expand All @@ -105,6 +108,8 @@ public void BeginRow(double? height, bool hidden, XlsxStyle style)
public void SkipRows(int rowCount)
{
CloseLastRow();
if (CurrentRowNumber + rowCount > MaxRowNumbers)
throw new InvalidOperationException($"A worksheet can contain at most {MaxRowNumbers} rows ({CurrentRowNumber + rowCount} attempted)");
CurrentRowNumber += rowCount;
}

Expand Down

0 comments on commit b06f026

Please sign in to comment.