Repository navigation
Fix an integer overflow in the box blur for a huge stdDeviation - #1260
Closed
abdymazhit wants to merge 1 commit into
Closed
abdymazhit wants to merge 1 commit into
abdymazhit wants to merge 1 commit into
Conversation
create_box_gauss converts the ideal box width to i32, so for a sigma above roughly 1.4e9 device pixels it saturates to i32::MAX and `wl + 2` overflows: a panic with overflow checks, a wrapped box size in release builds. Both feGaussianBlur and feDropShadow reach it. The upper box size now saturates, and apply leaves the image transparent when a box is wider than 4 * 255 times the blurred length. Pixels past the edges are transparent, so such a box averages every channel below a quarter, which rounds to zero, and the passes after it blur a transparent image: no pixel changes where the blur did not overflow before. Fixes linebender#1258. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Superseded by #1255, thanks regardless! |
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.
Fixes #1258.
create_box_gaussconverts the ideal box width toi32, so for a σ above roughly 1.4·10⁹ device pixels it saturates toi32::MAX, andwl + 2overflows. With overflow checks this panics; in release builds the box size wraps.feGaussianBlurandfeDropShadowboth reach it.Changes:
wusaturates, so the box sizes stay valid odd widths.box_blur::applyleaves the image transparent, without blurring, when a box is wider than4 * 255times the blurred length (the width for horizontal boxes, the height for vertical ones). Pixels past the edges are transparent, so such a box sums at most255 * lenper channel and every average is below a quarter. That rounds to zero, and the passes after it blur a transparent image. Where the blur did not overflow before, no pixel changes.blur_radius * width, which overflowsusizeon 32-bit targets.Tests: three unit tests in
box_blur.rs:f32::MAXand infinity;Without the fix, the first two panic at
box_blur.rs:48undercargo test -p resvg --lib box_blur.cargo test --all --releasepasses, and both SVGs from the issue render with a debug build of the CLI.#1255 moves filter rendering to
filtra, which bounds σ withMAX_STD_DEV. This fixes the current renderer until then.🤖 Generated with Claude Code