Skip to content

PSD: drop non-finite values, no panic in Warp::apply / Rect::new (#1130) - #1131

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix-psd-nonfinite-and-panic-paths
Oct 13, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix-psd-nonfinite-and-panic-paths

Conversation

@vangel76

Copy link
Copy Markdown
Contributor

Fixes #1130

Cause

  • EngineData numbers use str::parse::<f64>(), which accepts nan/inf/-inf; descriptor doubles, the TySh transform, the PlLd quad, expA f32 values and 32-bit samples were taken as read. The importer forwarded them to font size, tracking, leading, position and scale.
  • Warp::apply indexed mesh directly (public cols/rows/mesh, invariant only checked in Warp::read), and Rect::new added without overflow handling.

Changes

  • EngineData: non-finite or overflowing literals are not numbers (so the style value is None); font size must be > 0 and is capped at 10 000, tracking and leading are clamped to +-100 000.
  • Descriptor doub/UntF/UnFl and PlLd read non-finite as 0 (Reader::f64_finite); a TySh transform with a non-finite entry becomes the identity; expA falls back to exposure 0, offset 0, gamma 1.
  • samples() (32-bit): NaN -> 0, +inf -> 1.0 (white, like the maximum of the integer depths), -inf -> 0.
  • Importer (psd_import.rs): set_vec2/set_scalar ignore non-finite values, text_doc guards scale, size, leading and box.
  • Warp::mesh_point returns Option using get() and saturating/checked math, apply leaves the point unchanged for a missing or short mesh or zero/huge cols/rows; Warp::read computes (3c+1)(3r+1) with checked math. Rect::new saturates.

Tests (each fails without its fix, verified by temporarily reverting)

  • engine_data::tests::non_finite_and_out_of_range_numbers_are_not_numbers
  • tests::non_finite_transform_and_exposure_values_are_dropped, tests::non_finite_32_bit_samples_become_finite, tests::rect_new_near_i32_max_saturates
  • placed::tests::custom_warp_with_a_missing_or_short_mesh_does_not_panic
  • psd_import::tests::non_finite_text_values_never_reach_the_layer (engine)

Commands run

  • cargo test -p effectcraft-psd, cargo test -p effectcraft-engine, cargo test -p effectcraft-media layered
  • cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --all
  • cargo xtask layers, cargo check --target wasm32-unknown-unknown -p effectcraft-psd -p effectcraft-engine

Not run: cargo xtask ci as a whole, the ui-egui tests, the full workspace test suite.

Left out

🤖 Generated with Claude Code

…amples; no panic in Warp::apply or Rect::new (storytold#1130)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit e02c60c into storytold:main Oct 13, 2026
h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 13, 2026
…port formatting (#1149)

The six PSD PRs merged one by one leave #1131's test calling samples()/to_rgb(), which #1139
replaced; vangel76's integration draft #1149 has the adapted version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon

echelon commented Oct 13, 2026

Copy link
Copy Markdown
Member

Merged. Thank you for the contribution, @vangel76! It landed on main together with a batch of other community PRs, after a full workspace build and test run. If you are not on our Discord yet, please join us: https://discord.gg/artcraft

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.

PSD: non-finite values from descriptors/EngineData/32-bit samples reach layers; Warp::apply and Rect::new can panic

3 participants