Skip to content

Fix out-of-bounds panics when rendering malformed tables - #289

Closed
jmueller209 wants to merge 1 commit into
jugglerchris:mainfrom
jmueller209:fix-malformed-table-panics
Closed

jmueller209 wants to merge 1 commit into
jugglerchris:mainfrom
jmueller209:fix-malformed-table-panics

Conversation

@jmueller209

Copy link
Copy Markdown

Fix out-of-bounds panics when rendering malformed HTML tables

Description:
Hi! While building an offline Wikipedia database and parsing large amounts of raw HTML dumps, I ran into a couple of hard panics in text_renderer.rs.

The Problem:
When the parser encounters heavily malformed HTML (e.g. rowspan or colspan values completely out of sync with actual row content, or missing tags), the computed cell and table widths become distorted. This caused two out-of-bounds panics when the renderer attempts to slice arrays and strings using these miscalculated dimensions.

The Fix:
This PR adds boundary checks (clamping via .min() and .max()) in two places to prevent the panics:

  1. In BorderHoriz::to_string: Prevents out-of-bounds slicing on the self.segments array.
  2. In append_columns_with_borders: Prevents out-of-bounds slicing on the spaces padding string.

With these fixes, the library degrades gracefully and simply renders the broken layout as best as it can, instead of crashing the thread.

@jugglerchris

Copy link
Copy Markdown
Owner

I have addressed the root causes in #290, but thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants