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

Markdown.ToHtml throws IndexOutOfRangeException for lastBlock in GetCurrentDefinitionList #839

Closed
mschessler opened this issue Jan 1, 2025 · 0 comments · Fixed by #843
Closed

Comments

@mschessler
Copy link

Tested Version: newest commit d1233ff on main

I did not really take a closer look why this is happening but the problem is DefinitionListParser.GetCurrentDefinitionList() calling previousParent with index = -1 if the lastBlock is a BlankLineBlock.

if (lastBlock is BlankLineBlock)
{
    lastBlock = previousParent[index - 1];
    previousParent.RemoveAt(index);
}

Casting -1 to an unsigned int is then problematic.

grafik

Reproducer:

var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
var result = Markdown.ToHtml("+\r\n\r\n+\r\n\r\n\t\f\r\n~\t", pipeline);

or

var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
var result = Markdown.ToHtml("- \r\n\r\n\t\f\r\n~\t", pipeline);

Stacktrace:

ThrowHelper removed for Stacktrace.

at Markdig.Syntax.ContainerBlock.get_Item(Int32 index) in \src\Markdig\Syntax\ContainerBlock.cs:line 220
at Markdig.Extensions.DefinitionLists.DefinitionListParser.GetCurrentDefinitionList(ParagraphBlock paragraphBlock, ContainerBlock previousParent) in \src\Markdig\Extensions\DefinitionLists\DefinitionListParser.cs:line 111
at Markdig.Extensions.DefinitionLists.DefinitionListParser.TryOpen(BlockProcessor processor) in \src\Markdig\Extensions\DefinitionLists\DefinitionListParser.cs:line 53
at Markdig.Parsers.BlockProcessor.TryOpenBlocks(BlockParser[] parsers) in \src\Markdig\Parsers\BlockProcessor.cs:line 821
at Markdig.Parsers.BlockProcessor.TryOpenBlocks() in \src\Markdig\Parsers\BlockProcessor.cs:line 763
at Markdig.Parsers.BlockProcessor.ProcessLine(StringSlice newLine) in \src\Markdig\Parsers\BlockProcessor.cs:line 501
at Markdig.Parsers.MarkdownParser.ProcessBlocks(BlockProcessor blockProcessor, String text) in \src\Markdig\Parsers\MarkdownParser.cs:line 113
at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context) in \src\Markdig\Parsers\MarkdownParser.cs:line 56
at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context) in \src\Markdig\Markdown.cs:line 101
at FuzzTest.Program.Main(String[] args) in \FuzzingTargets\MarkdigFuzzer\Program.cs:line 14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants