Repository navigation
EPS import: bound the stitched-gradient builder - #929
Merged
Merged
Conversation
Cap the stops taken from a stitching function (1024), bound linear_points by depth and by a shared visit count, and stop eval from copying the whole Functions array on every call. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Member
|
Thanks, @haranishi! Merged after a full CI run. A self-referencing |
4 tasks done
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.
What and why
Three ways a small EPS/PS/AI program could freeze or crash the import through a stitching function (
/FunctionType 3) inshfill:gradient()made one stop per/Boundsentry (linear_points), and every stop callseval, which rebuiltBoundsand copied the wholeFunctionsarray on each call: O(N²). A program that builds 40,000 bounds in a loop (a few operations each) took 11 s, and the import is synchronous. The non-linear case was already capped at 32 samples.F /Functions [ F ] put) madelinear_pointsrecurse until the stack overflowed, which aborts the process (vectorcraft_engine::guardcannot catch an abort).evalalready stops at depth 8;linear_pointsdid not.Functionsarrays of 1025 references to one child, three levels deep, are 1025³ visits forlinear_pointsfrom a tiny file (it did not finish in 60 s).What changes, in
crates/eps/src/import/graphics.rs:MAX_STITCH_STOPS = 1024: more bounds, or more than 1025 pieces, and the function is sampled (33 stops) like any other function. Up to 1024 bounds keep their exact stops, so ordinary gradients are unchanged.linear_pointstakes the depth (it gives up past 8, asevaldoes) and a visit counter shared by the whole recursion (it gives up past 2 × 1025 visits; a well-formed stitch of linear pieces needs at most 1026).Functionsis length-checked before it is copied.eval's stitching branch readsFunctionsthrough the borrow and copies only the piece it recurses into, instead of the whole array on every call and at every live recursion level.MAX_OPS) still does not account for the workevaldoes on large arrays. I left that as it is.How it was tested
Five new tests in
tests_generators.rs. They assert stop counts and outcomes; there is no timing.gradients_stitched_from_linear_pieces_keep_or_sample_their_stops: 3 bounds give the exact 5 stops; 1024 bounds give 1026; 1025 bounds are sampled (33). Before the fix the last case gave 1027 stops.a_stitching_function_with_one_piece_but_many_bounds_is_sampled: 2000 bounds on one piece give 33 stops (2002 before).a_gradient_with_a_functions_array_past_the_cap_is_sampled: 1026 pieces with 1000 bounds give 33 stops (1002 before).a_stitching_function_that_refers_to_itself_is_rejected_not_crashed: the import returns, keeps what was drawn before the error and reports it (before the fix the process aborts with SIGABRT).a_deeply_shared_stitching_function_is_sampled_not_walked: 1025 references to a child, three levels deep, are sampled at once (before the fix it did not finish in 60 s).cargo xtask cipasses after rebasing onto the currentmain(all 7 steps, 145 tests invectorcraft-eps).Checklist
cargo xtask cipasses (fmt, clippy, tests, assets, brands, layers, wasm).unwrap(),expect(),panic!,unreachable!,todo!orunimplemented!outside tests, and no unchecked indexing on data from files, parameters ormessages. Errors are returned as
Resultand shown to the user(why and how).
ASSETS.md. (There are no new assets.)🤖 Generated with Claude Code