From a2a9c4f76ef5a5c32108e36f7c47f8d310322252 Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Mon, 29 Jul 2024 23:28:18 +0200 Subject: [PATCH] fix infinite loop with empty list definition (fixes #311) --- parser/block.go | 4 +++- parser/parser_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/parser/block.go b/parser/block.go index 4b7326e..3ef5334 100644 --- a/parser/block.go +++ b/parser/block.go @@ -1652,7 +1652,9 @@ func (p *Parser) paragraph(data []byte) int { if p.extensions&DefinitionLists != 0 { if i < len(data)-1 && data[i+1] == ':' { listLen := p.list(data[prev:], ast.ListTypeDefinition, 0, '.') - return prev + listLen + if listLen > 0 { + return prev + listLen + } } } diff --git a/parser/parser_test.go b/parser/parser_test.go index a845041..32b39de 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -4,6 +4,12 @@ import ( "testing" ) +func TestBug311(t *testing.T) { + str := "~~~~\xb4~\x94~\x94~\xd1\r\r:\xb4\x94\x94~\x9f~\xb4~\x94~\x94\x94" + p := New() + p.Parse([]byte(str)) +} + func TestIsFenceLine(t *testing.T) { tests := []struct { data []byte