wrap_lines split an over-long word by re-measuring and copying the
rest of the word for every piece it cut, and only checked its line
limit once the word was done, so one long word in a narrow text box
cost word length x pieces. Each new word also re-measured the whole
line built so far.
Line and piece widths are now running sums of glyph widths (the same
sum text_width makes), so every character is measured once, and the
line limit is checked while a word is being split. The lines produced
are unchanged; a test compares them with the old wrapper.
Addresses CodeRabbit security findings (CWE-407).
What was wrong
wrap_lines(PDF export of shape text and wrapped cells) split an over-long word by re-measuring and copying the rest of the word for each piece it cut. It also checked its 2,000-line limit only after finishing a word, so one long word in a narrow text box cost word length x pieces. Each new word also re-measured the whole line so far.What changed
text_widthmakes, so each character is measured once.Blast radius: PDF text wrapping. The lines produced are unchanged; a test compares them with the old wrapper across fonts, sizes and widths.
Tests:
wrap_lines_matches_the_remeasuring_wrapper,wrapping_a_long_word_in_a_narrow_box_stops_at_the_line_limit, existingbands_unit.Checks run
cargo test -p gridcraft-engine -p gridcraft-charton a local branch combining this PR with the other security fixes opened alongside it (all pass: engine 817 unit, 101 integration; chart 46)cargo check -p gridcraft-engine -p gridcraft-chart --testson this branch alonerustfmt --checkon the changed filesChecks not run
cargo clippy, the full workspace test suite, the UI crate, macOS and Windows buildsSummary by CodeRabbit