Parsing of spec.md throws IndexOutOfRangeException #611

Closed
opened 2026-01-29 14:41:06 +00:00 by claunia · 3 comments
Owner

Originally created by @josefpihrt on GitHub (Jul 24, 2023).

Version: 0.31.0

Repro:

string markdown = File.ReadAllText("src/Markdig.Benchmarks/spec.md");

MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();

MarkdownDocument document = Markdown.Parse(markdown, pipeline);

Stack trace:

Index was outside the bounds of the array.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Markdig.Helpers.ThrowHelper.ThrowIndexOutOfRangeException()
   at Markdig.Extensions.DefinitionLists.DefinitionListParser.GetCurrentDefinitionList(ParagraphBlock paragraphBlock, ContainerBlock previousParent)
   at Markdig.Extensions.DefinitionLists.DefinitionListParser.TryOpen(BlockProcessor processor)
   at Markdig.Parsers.BlockProcessor.TryOpenBlocks(BlockParser[] parsers)
   at Markdig.Parsers.BlockProcessor.TryOpenBlocks()
   at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine)
   at Markdig.Parsers.MarkdownParser.ProcessBlocks(BlockProcessor blockProcessor, LineReader lineReader)
   at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context)
   at Markdig.Markdown.Parse(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context)
Originally created by @josefpihrt on GitHub (Jul 24, 2023). Version: 0.31.0 Repro: ```cs string markdown = File.ReadAllText("src/Markdig.Benchmarks/spec.md"); MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); MarkdownDocument document = Markdown.Parse(markdown, pipeline); ``` Stack trace: ``` Index was outside the bounds of the array. System.IndexOutOfRangeException: Index was outside the bounds of the array. at Markdig.Helpers.ThrowHelper.ThrowIndexOutOfRangeException() at Markdig.Extensions.DefinitionLists.DefinitionListParser.GetCurrentDefinitionList(ParagraphBlock paragraphBlock, ContainerBlock previousParent) at Markdig.Extensions.DefinitionLists.DefinitionListParser.TryOpen(BlockProcessor processor) at Markdig.Parsers.BlockProcessor.TryOpenBlocks(BlockParser[] parsers) at Markdig.Parsers.BlockProcessor.TryOpenBlocks() at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine) at Markdig.Parsers.MarkdownParser.ProcessBlocks(BlockProcessor blockProcessor, LineReader lineReader) at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context) at Markdig.Markdown.Parse(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context) ```
claunia added the bugPR Welcome! labels 2026-01-29 14:41:06 +00:00
Author
Owner

@lofcz commented on GitHub (Jul 28, 2023):

The same error frequently occurs with this stack trace:

   at Markdig.Helpers.StringLineGroup.Iterator.NextCharNewLine()
   at Markdig.Helpers.LinkHelper.TryParseLabel[T](T& lines, Boolean allowEmpty, String& label, SourceSpan& labelSpan)
   at Markdig.Helpers.LinkHelper.TryParseLinkReferenceDefinition[T](T& text, String& label, String& url, String& title, SourceSpan& labelSpan, SourceSpan& urlSpan, SourceSpan& titleSpan)
   at Markdig.Syntax.LinkReferenceDefinition.TryParse[T](T& text, LinkReferenceDefinition& block)
   at Markdig.Parsers.ParagraphBlockParser.TryMatchLinkReferenceDefinition(StringLineGroup& lines, BlockProcessor state)
   at Markdig.Parsers.ParagraphBlockParser.Close(BlockProcessor processor, Block block)
   at Markdig.Parsers.BlockProcessor.Close(Int32 index)
   at Markdig.Parsers.BlockProcessor.CloseAll(Boolean force)
   at Markdig.Parsers.MarkdownParser.ProcessBlocks(BlockProcessor blockProcessor, LineReader lineReader)
   at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context)
@lofcz commented on GitHub (Jul 28, 2023): The same error frequently occurs with this stack trace: ``` at Markdig.Helpers.StringLineGroup.Iterator.NextCharNewLine() at Markdig.Helpers.LinkHelper.TryParseLabel[T](T& lines, Boolean allowEmpty, String& label, SourceSpan& labelSpan) at Markdig.Helpers.LinkHelper.TryParseLinkReferenceDefinition[T](T& text, String& label, String& url, String& title, SourceSpan& labelSpan, SourceSpan& urlSpan, SourceSpan& titleSpan) at Markdig.Syntax.LinkReferenceDefinition.TryParse[T](T& text, LinkReferenceDefinition& block) at Markdig.Parsers.ParagraphBlockParser.TryMatchLinkReferenceDefinition(StringLineGroup& lines, BlockProcessor state) at Markdig.Parsers.ParagraphBlockParser.Close(BlockProcessor processor, Block block) at Markdig.Parsers.BlockProcessor.Close(Int32 index) at Markdig.Parsers.BlockProcessor.CloseAll(Boolean force) at Markdig.Parsers.MarkdownParser.ProcessBlocks(BlockProcessor blockProcessor, LineReader lineReader) at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context) ```
Author
Owner

@Yaro77 commented on GitHub (Sep 2, 2023):

@JosefPihrt Can't reproduce on latest master (7d40bc11) with .net7. spec.md parsed without any issue.

@Yaro77 commented on GitHub (Sep 2, 2023): @JosefPihrt Can't reproduce on latest master (7d40bc11) with .net7. spec.md parsed without any issue.
Author
Owner

@josefpihrt commented on GitHub (Sep 2, 2023):

I also cannot reproduce it on latest master.

@josefpihrt commented on GitHub (Sep 2, 2023): I also cannot reproduce it on latest master.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#611