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

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

📋 Pull Request Information

Original PR: https://github.com/xoofx/markdig/pull/710
Author: @valterc
Created: 4/18/2023
Status: Merged
Merged: 4/22/2023
Merged by: @xoofx

Base: masterHead: fix-line-group-oob


📝 Commits (3)

📊 Changes

3 files changed (+65 additions, -3 deletions)

View changed files

📝 src/Markdig.Tests/TestStringSliceList.cs (+35 -0)
📝 src/Markdig.Tests/TestYamlFrontMatterExtension.cs (+24 -0)
📝 src/Markdig/Helpers/StringLineGroup.cs (+6 -3)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/xoofx/markdig/pull/710 **Author:** [@valterc](https://github.com/valterc) **Created:** 4/18/2023 **Status:** ✅ Merged **Merged:** 4/22/2023 **Merged by:** [@xoofx](https://github.com/xoofx) **Base:** `master` ← **Head:** `fix-line-group-oob` --- ### 📝 Commits (3) - [`a911877`](https://github.com/xoofx/markdig/commit/a9118774a8cd4c8dc0d996d1dc0163944d1e794b) Added line count check to avoid out of bounds - [`cd5d11e`](https://github.com/xoofx/markdig/commit/cd5d11eeffc27d97e6d43243114f1c8c811f4def) Fix index check - [`512b282`](https://github.com/xoofx/markdig/commit/512b28256a2e01417213dbe419baa18f630c6acf) Improved tests ### 📊 Changes **3 files changed** (+65 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/Markdig.Tests/TestStringSliceList.cs` (+35 -0) 📝 `src/Markdig.Tests/TestYamlFrontMatterExtension.cs` (+24 -0) 📝 `src/Markdig/Helpers/StringLineGroup.cs` (+6 -3) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 14:51:11 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#1194