Markdown.ToHtml throws IndexOutOfRangeException #268

Closed
opened 2026-01-29 14:32:21 +00:00 by claunia · 2 comments
Owner

Originally created by @Metalnem on GitHub (Feb 5, 2019).

The latest version of Markdig can still throw IndexOutOfRangeException from Markdown.ToHtml method (this is different from #276). This time I've collected all the unique stack traces, and minimized the inputs:

IndexOutOfRangeException 1

var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
Markdown.ToHtml("+-\n|\n+", pipeline);
Exception has occurred: CLR/System.IndexOutOfRangeException
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Markdig.dll: 'Index was outside the bounds of the array.'
   at Markdig.Helpers.StringSlice.TrimStart()
   at Markdig.Extensions.Tables.GridTableParser.SetRowSpanState(List`1 columns, StringSlice line, Boolean& isHeaderRow, Boolean& hasRowSpan)
   at Markdig.Extensions.Tables.GridTableParser.HandleNewRow(BlockProcessor processor, GridTableState tableState, Table gridTable)
   at Markdig.Parsers.BlockProcessor.TryContinueBlocks()
   at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine)
   at Markdig.Parsers.MarkdownParser.ProcessBlocks()
   at Markdig.Parsers.MarkdownParser.Parse()
   at Markdig.Markdown.ToHtml(String markdown, TextWriter writer, MarkdownPipeline pipeline)
   at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline)

IndexOutOfRangeException 2

var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
Markdown.ToHtml("+--\n|\n+0", pipeline);
Exception has occurred: CLR/System.IndexOutOfRangeException
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Markdig.dll: 'Index was outside the bounds of the array.'
   at Markdig.Helpers.StringSlice.TrimEnd()
   at Markdig.Extensions.Tables.GridTableParser.SetRowSpanState(List`1 columns, StringSlice line, Boolean& isHeaderRow, Boolean& hasRowSpan)
   at Markdig.Extensions.Tables.GridTableParser.HandleNewRow(BlockProcessor processor, GridTableState tableState, Table gridTable)
   at Markdig.Parsers.BlockProcessor.TryContinueBlocks()
   at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine)
   at Markdig.Parsers.MarkdownParser.ProcessBlocks()
   at Markdig.Parsers.MarkdownParser.Parse()
   at Markdig.Markdown.ToHtml(String markdown, TextWriter writer, MarkdownPipeline pipeline)
   at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline)

IndexOutOfRangeException 3

var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
Markdown.ToHtml("+-\n|\n+\n0", pipeline);
Exception has occurred: CLR/System.IndexOutOfRangeException
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Markdig.dll: 'Index was outside the bounds of the array.'
   at Markdig.Extensions.Tables.Table.IsValid()
   at Markdig.Extensions.Tables.GridTableParser.TryContinue(BlockProcessor processor, Block block)
   at Markdig.Parsers.BlockProcessor.TryContinueBlocks()
   at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine)
   at Markdig.Parsers.MarkdownParser.ProcessBlocks()
   at Markdig.Parsers.MarkdownParser.Parse()
   at Markdig.Markdown.ToHtml(String markdown, TextWriter writer, MarkdownPipeline pipeline)
   at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline)

IndexOutOfRangeException 4

var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
Markdown.ToHtml("+-\n|\n+0", pipeline);
Exception has occurred: CLR/System.IndexOutOfRangeException
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Markdig.dll: 'Index was outside the bounds of the array.'
   at Markdig.Extensions.Tables.Table.IsValid()
   at Markdig.Extensions.Tables.GridTableParser.Close(BlockProcessor processor, Block block)
   at Markdig.Parsers.BlockProcessor.Close(Int32 index)
   at Markdig.Parsers.BlockProcessor.CloseAll(Boolean force)
   at Markdig.Parsers.MarkdownParser.ProcessBlocks()
   at Markdig.Parsers.MarkdownParser.Parse()
   at Markdig.Markdown.ToHtml(String markdown, TextWriter writer, MarkdownPipeline pipeline)
   at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline)

I'm using Markdig 0.15.7 and .NET Core 2.2.103.

Found via SharpFuzz.

Originally created by @Metalnem on GitHub (Feb 5, 2019). The latest version of Markdig can still throw **IndexOutOfRangeException** from **Markdown.ToHtml** method (this is different from #276). This time I've collected all the unique stack traces, and minimized the inputs: ### IndexOutOfRangeException 1 ```csharp var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); Markdown.ToHtml("+-\n|\n+", pipeline); ``` ``` Exception has occurred: CLR/System.IndexOutOfRangeException An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Markdig.dll: 'Index was outside the bounds of the array.' at Markdig.Helpers.StringSlice.TrimStart() at Markdig.Extensions.Tables.GridTableParser.SetRowSpanState(List`1 columns, StringSlice line, Boolean& isHeaderRow, Boolean& hasRowSpan) at Markdig.Extensions.Tables.GridTableParser.HandleNewRow(BlockProcessor processor, GridTableState tableState, Table gridTable) at Markdig.Parsers.BlockProcessor.TryContinueBlocks() at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine) at Markdig.Parsers.MarkdownParser.ProcessBlocks() at Markdig.Parsers.MarkdownParser.Parse() at Markdig.Markdown.ToHtml(String markdown, TextWriter writer, MarkdownPipeline pipeline) at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline) ``` ### IndexOutOfRangeException 2 ```csharp var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); Markdown.ToHtml("+--\n|\n+0", pipeline); ``` ``` Exception has occurred: CLR/System.IndexOutOfRangeException An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Markdig.dll: 'Index was outside the bounds of the array.' at Markdig.Helpers.StringSlice.TrimEnd() at Markdig.Extensions.Tables.GridTableParser.SetRowSpanState(List`1 columns, StringSlice line, Boolean& isHeaderRow, Boolean& hasRowSpan) at Markdig.Extensions.Tables.GridTableParser.HandleNewRow(BlockProcessor processor, GridTableState tableState, Table gridTable) at Markdig.Parsers.BlockProcessor.TryContinueBlocks() at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine) at Markdig.Parsers.MarkdownParser.ProcessBlocks() at Markdig.Parsers.MarkdownParser.Parse() at Markdig.Markdown.ToHtml(String markdown, TextWriter writer, MarkdownPipeline pipeline) at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline) ``` ### IndexOutOfRangeException 3 ```csharp var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); Markdown.ToHtml("+-\n|\n+\n0", pipeline); ``` ``` Exception has occurred: CLR/System.IndexOutOfRangeException An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Markdig.dll: 'Index was outside the bounds of the array.' at Markdig.Extensions.Tables.Table.IsValid() at Markdig.Extensions.Tables.GridTableParser.TryContinue(BlockProcessor processor, Block block) at Markdig.Parsers.BlockProcessor.TryContinueBlocks() at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine) at Markdig.Parsers.MarkdownParser.ProcessBlocks() at Markdig.Parsers.MarkdownParser.Parse() at Markdig.Markdown.ToHtml(String markdown, TextWriter writer, MarkdownPipeline pipeline) at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline) ``` ### IndexOutOfRangeException 4 ```csharp var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); Markdown.ToHtml("+-\n|\n+0", pipeline); ``` ``` Exception has occurred: CLR/System.IndexOutOfRangeException An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Markdig.dll: 'Index was outside the bounds of the array.' at Markdig.Extensions.Tables.Table.IsValid() at Markdig.Extensions.Tables.GridTableParser.Close(BlockProcessor processor, Block block) at Markdig.Parsers.BlockProcessor.Close(Int32 index) at Markdig.Parsers.BlockProcessor.CloseAll(Boolean force) at Markdig.Parsers.MarkdownParser.ProcessBlocks() at Markdig.Parsers.MarkdownParser.Parse() at Markdig.Markdown.ToHtml(String markdown, TextWriter writer, MarkdownPipeline pipeline) at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline) ``` I'm using Markdig 0.15.7 and .NET Core 2.2.103. Found via [SharpFuzz](https://github.com/Metalnem/sharpfuzz).
claunia added the bugPR Welcome! labels 2026-01-29 14:32:21 +00:00
Author
Owner

@rstm-sf commented on GitHub (Nov 17, 2022):

Fixed by https://github.com/xoofx/markdig/pull/404?

@rstm-sf commented on GitHub (Nov 17, 2022): Fixed by https://github.com/xoofx/markdig/pull/404?
Author
Owner

@Metalnem commented on GitHub (Jun 9, 2023):

Yes!

@Metalnem commented on GitHub (Jun 9, 2023): Yes!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#268