[PR #710] Add line count check to avoid out of range #1199

Open
opened 2026-01-29 14:51:15 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/xoofx/markdig/pull/710

State: closed
Merged: Yes


IndexOutOfRangeException is thrown in StringLineGroup when calling Iterator.NextChar
8155a1e3d6/src/Markdig/Helpers/StringLineGroup.cs (L276)

The exception occurs when trying to advance to the next line when the StringLineGroup is at capacity (capacity == line_count)

8155a1e3d6/src/Markdig/Helpers/StringLineGroup.cs (L339)

This exception is kind of an edge case and does not happen often because LeafBlock and other parts that use the StringLineGroup provision some extra capacity in advance and when capacity is needed it is increased by a factor of 2, so it's not very common that the needed capacity matches the line count.

**Original Pull Request:** https://github.com/xoofx/markdig/pull/710 **State:** closed **Merged:** Yes --- IndexOutOfRangeException is thrown in [StringLineGroup](https://github.com/xoofx/markdig/blob/master/src/Markdig/Helpers/StringLineGroup.cs) when calling Iterator.NextChar https://github.com/xoofx/markdig/blob/8155a1e3d657dbe17c14e5612791b4a7d7f3da68/src/Markdig/Helpers/StringLineGroup.cs#L276 The exception occurs when trying to advance to the next line when the StringLineGroup is at capacity (capacity == line_count) https://github.com/xoofx/markdig/blob/8155a1e3d657dbe17c14e5612791b4a7d7f3da68/src/Markdig/Helpers/StringLineGroup.cs#L339 This exception is kind of an edge case and does not happen often because `LeafBlock` and other parts that use the StringLineGroup provision some extra capacity in advance and when capacity is needed it is increased by a factor of 2, so it's not very common that the needed capacity matches the line count.
claunia added the pull-request label 2026-01-29 14:51:15 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#1199