Fix out-of-bounds panics when rendering malformed tables - #289
Closed
jmueller209 wants to merge 1 commit into
Closed
jmueller209 wants to merge 1 commit into
jmueller209 wants to merge 1 commit into
Conversation
Owner
|
I have addressed the root causes in #290, but thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
rowspanorcolspanvalues 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:BorderHoriz::to_string: Prevents out-of-bounds slicing on theself.segmentsarray.append_columns_with_borders: Prevents out-of-bounds slicing on thespacespadding string.With these fixes, the library degrades gracefully and simply renders the broken layout as best as it can, instead of crashing the thread.