Skip to content

Skip non-integer colour transform values instead of zeroing them - #1491

Open
Silvertree2010 wants to merge 1 commit into
storytold:mainfrom
Silvertree2010:fix/h3572-colour-object-with-a-non-integer
Open

Silvertree2010 wants to merge 1 commit into
storytold:mainfrom
Silvertree2010:fix/h3572-colour-object-with-a-non-integer

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/engine/src/cmd.rs:~425 (color_value) (no existing issue): Colour object with a non-integer transform value gets that transform set to 0, which turns the colour black.

Cause

color_value converts each transform value with as_i64() and i32::try_from. A string, a float or an out-of-range number gives None, and ColorTransform::from_xml turns None into 0. The result is LumMod(0) (black) or Alpha(0) (fully transparent), with no error.

Fix

In color_value, a transform that carries a value is now skipped when its value isn't a usable i32. The rest of the colour is kept. Transforms without a value (comp, inv, gray) are unaffected. A regression test covers a string, 75000.0, 0.75 and a number above the i32 range, and checks that a valid integer still works.

Verified

  • Regression test cmd::tests::a_non_integer_colour_transform_is_skipped_not_zeroed: fails on main without the fix and passes with it (cargo test -p deckcraft-engine --lib a_non_integer_colour).
  • cargo xtask ci passes except backstage::tests::start_screen_opens_the_palette_and_preferences, which also fails on main without this change.

Not changed

ColorTransform::from_xml still defaults a missing value to 0, because other callers pass it that way. The whole colour is not rejected, so one bad key doesn't fail a load.

🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models

Summary by CodeRabbit

  • Bug Fixes
    • Color adjustments with non-integer, fractional, or out-of-range values are skipped instead of being applied with a default value.
    • Valid integer values continue to work, and adjustments without a value remain eligible.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

color_value now skips value-bearing color transforms when their values do not convert to i32. A test checks invalid and valid lumMod values.

Changes: Color transform validation

Layer / File(s) Summary
Validate color transform values
crates/engine/src/cmd.rs
color_value adds a value-bearing transform only when its value converts to i32. The test checks string, floating-point, fractional, out-of-range, and valid integer lumMod values.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: aiongg, echelon

Merge Risk: Minimal · up to 0bce1

Invalid colour transform values are now skipped instead of turning a colour black or transparent. The change is small, tested, and has no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: colour transforms with non-integer values are skipped rather than zeroed. The raw summary and objectives both confirm that color_value now skips a recognised transfor…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: colour transforms with non-integer values are skipped rather than zeroed. The raw summary and objectives both confirm that color_value now skips a recognised transform when its value is not a usable signed 32-bit integer, instead of passing None and adding a default-valued transform. The title is specific, concise, and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1e79c63 and 0bce106.

Files selected for processing: 1

  • crates/engine/src/cmd.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@Harrison-Booth

Copy link
Copy Markdown
Contributor

Review checks for #1491

CARGO_BUILD_JOBS=2 cargo test -p deckcraft-engine a_non_integer_colour_transform_is_skipped_not_zeroed -- --nocapture passed (1 test). The submitted regression skips string, integer-shaped float, fractional float, and out-of-range lumMod values while retaining integer 75000.

I also ran a temporary reviewer-only matrix through color_value: null, 75000.0, 0.0, and 0.75 are skipped for value-bearing lumMod; -2 remains LumMod(-2) and zero remains LumMod(0). Valueless comp, inv, and gray remain their corresponding transforms. These parser results leave the base colour unchanged for the invalid values. I did not broaden the checks to other colour parsing paths.

@echelon

echelon commented Oct 30, 2026

Copy link
Copy Markdown
Member

Thanks for the fix! It's sound, but #1432 and #1345 both rewrite the same color_value transform loop, so I'm holding these three until the mods format is settled (see #1432). After that, a rebase should be small.

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReviewerA — source-read COMMENT (not an approval)

I read the code hunk: a colour transform whose value is not an integer (for example 1.5 or a string) is skipped instead of being turned into 0, which used to apply e.g. a 0% alpha or lum. The t.value().is_none() check keeps transforms without values. Correct; the test is in the diff.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

@aiongg aiongg added the bugfix Fixes something that is broken: wrong result, crash, data loss label Nov 4, 2026

@aiongg aiongg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (Opus). Not a maintainer decision.

No blocking problems found (not certain).

color_value now drops a value-bearing colour transform whose JSON value is not a usable i32, so it is no longer turned into 0. Valueless transforms and the rest of the colour are kept.

  • crates/engine/src/cmd.rs:416-421: the n.is_some() || t.value().is_none() check keeps comp/inv/gray and keeps every valid integer, including 0 and negative values. Only a missing, string, float or out-of-range value is dropped.
  • crates/engine/src/cmd.rs:645-653: the test covers a string, an integer-shaped float, a fraction and a value above the i32 range, plus one valid integer.
  • crates/pptx/src/read/dml.rs:58 still turns a missing or unparsable val into 0 through ColorTransform::from_xml, and crates/pptx/src/xml.rs:72-73 clamps out-of-range values where this PR drops them. This is left for a separate change, as the description says.
  • The same transform loop is also changed by the ordered mods work in #1432 and #1345, so this change will need a small rebase onto whichever format lands.

Claims checked:

  • verified: A transform that carries a value is skipped, instead of being set to 0, when its value is a string, a float or out of the i32 range. (crates/engine/src/cmd.rs:416 gives n = None for non-i64 or out-of-range values. cmd.rs:419 pushes the transform only if n is Some or the transform has no value. crat…
  • verified: The rest of the colour is kept; one bad key does not reject the colour. (crates/engine/src/cmd.rs:415-424: the loop continues past a skipped key and still returns Some(c).)
  • verified: Transforms without a value (comp, inv, gray) are unaffected. (crates/color/src/lib.rs:321-338: value() returns None for Comp, Inv and Gray, so cmd.rs:419 still pushes them.)
  • verified: ColorTransform::from_xml is not changed and still defaults a missing value to 0 for its other callers. (crates/color/src/lib.rs:340-341 is unchanged. Its other caller is crates/pptx/src/read/dml.rs:58.)
  • verified: A regression test covers a string, 75000.0, 0.75 and a number above the i32 range, and checks that a valid integer still works. (crates/engine/src/cmd.rs:645-653 asserts that the mods are empty for each bad value and that integer 75000 gives LumMod(75000).)

Recommendation: merge, after a maintainer's decision.

Reviewed at 1e79c63.

@autocraft-bot

autocraft-bot Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Automated message. Not a maintainer decision.

This branch conflicts with main. Could you merge or rebase main into it? The conflict needs a person to resolve.

Found while testing crates/engine/src/cmd.rs:~425 (color_value)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Silvertree2010
Silvertree2010 force-pushed the fix/h3572-colour-object-with-a-non-integer branch from 1e79c63 to 0bce106 Compare November 15, 2026 17:24

@autocraft-bot autocraft-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (Opus). Not a maintainer decision.

Changes needed:

In color_value, a transform with a value is now skipped, rather than set to 0, when its JSON value is not an i32. Transforms without a value (comp, inv, gray) are still kept.

  • crates/engine/src/cmd.rs:416-421: the filter n.is_some() || t.value().is_none() keeps valid integers and valueless transforms, and drops strings, floats, null and out-of-range numbers. The base colour is unchanged.
  • The regression test covers a string, an integer-shaped float, a fractional float and a value above the i32 range, and checks that a valid integer still gives LumMod(75000).
  • issue 1432 rewrites the same transform loop in crates/engine/src/cmd.rs and adds equivalent filtering, so this change will need to be reconciled with it.

Claims checked:

  • verified: A value-bearing transform whose value is a string, a float or out of i32 range is now skipped instead of being set to 0 (crates/engine/src/cmd.rs:416 gives None for any non-i64 or out-of-range value. crates/engine/src/cmd.rs:419 pushes the transform only when n is Some or the transform has no value…
  • verified: Transforms without a value (comp, inv, gray) are unaffected, and the rest of the colour is kept (crates/color/src/lib.rs:321-338 returns None from value() for Comp, Inv and Gray, so crates/engine/src/cmd.rs:419 still pushes them. The base colour from crates/engine/src/cmd.rs:399-414 is unchanged)
  • verified: ColorTransform::from_xml still defaults a missing value to 0 for other callers (crates/color/src/lib.rs:341 val.unwrap_or(0) is unchanged. The other caller is crates/pptx/src/read/dml.rs:68)
  • unverified: A regression test covers a string, 75000.0, 0.75 and a number above i32, plus a valid integer (The test a_non_integer_colour_transform_is_skipped_not_zeroed in crates/engine/src/cmd.rs, added in the tests module after line 694)

Reviewed at 0bce106.

Recommendation: update the pull request; it will be reviewed again.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes something that is broken: wrong result, crash, data loss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants