Reject spline animations if the last value of keyTimes is not 1 [chromium/src : main]

0 views
Skip to first unread message

YISI YU (Gerrit)

unread,
5:34 AM (11 hours ago) 5:34 AM
to Fredrik Söderquist, Xianzhu Wang, Chromium LUCI CQ, AyeAye, Menard, Alexis, chromium...@chromium.org, Dirk Schulze, Olga Gerchikov, Stephen Chenney, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, kouhe...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Fredrik Söderquist and Xianzhu Wang

YISI YU voted and added 7 comments

Votes added by YISI YU

Auto-Submit+1
Commit-Queue+1

7 comments

Patchset-level comments
File-level comment, Patchset 9 (Latest):
YISI YU . resolved

Hello Fredrik. Hello Vacation. Sorry for the delay with this CL. It is now ready for review. PTAL!

The root cause of this issue is that we omitted the check for the abnormal case where the last value of keyTimes is not 1 for spline animations, which leads to us getting an incorrect keyTimes index and further causes from_percent and to_percent to be equal.

Such cases can be avoided by improving the check for keyTimes.

Commit Message
Line 7, Patchset 2:FIXUP: DCHECK when calculate svg animation
Fredrik Söderquist . resolved

This is not a great prefix. How about a more descriptive description, something along the lines of:

Fix handling of zero-length keyTimes intervals

?

YISI YU

Done

File third_party/blink/renderer/core/svg/svg_animation_element.cc
Line 454, Patchset 2: ? std::numeric_limits<float>::epsilon()
Xianzhu Wang . resolved

1. The sign may change here if `from` is less than `to`. Should we keep the sign?
2. In extreme cases, the result can be infinite. Do we need the result to be finite?

Do you know if we already have a function in css/svg code for percent or float interpolation?

YISI YU

Thansk for your reply.

1. It appears that `to_percent` will always be greater than `from_percent`, because when parsing `keyTimes`, [ParseKeyTimes](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/svg/svg_animation_element.cc;l=193;bpv=1;bpt=1?q=ParseKeyTimes&ss=chromium) ensures that the sequence is strictly increasing.

2. CSS Keyframes has a similar issue, but the CSS specification stipulates that [all keyframe groups will be merged](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/keyPoints). For the same property, the latter one takes effect. Its code implementation is located [here](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/animation/css/css_animations.cc;l=473).

3. A similar type of interpolation calculation is color interpolation ([ColorInterpolation::InterpolateColors](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/graphics/color.h;l=256;bpv=1;bpt=1)): it does not has a range restriction, but provides [Color::ResolveNonFiniteValues](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/graphics/color.h;l=397;bpv=1;bpt=1) to handle cases involving `NaN` and `inf`.

The fix now works almost the same as when Chrome's DCHECK is off, and Safari behaves pretty much the same as our current code does too.

Fredrik Söderquist

This is unnecessarily complicated. If the key-times interval is zero, then the result would just map to one of the possible end-points - 0 or 1. I think I'd go with zero here.

YISI YU

This extreme case won't happen if `keyTimes` are well checked. The core fix is to improve the check for spline in `CheckAnimationParameters()`, rather than individually checking for these edge cases.

Line 559, Patchset 2: DCHECK_GT(to_percent, from_percent);
Fredrik Söderquist . resolved

This ought to be `DCHECK_GE()` I guess? At least in the key-times branch above. It probably makes sense to move the computation of `effective_percent` up into the `key_times_count` if-else statement blocks above.

YISI YU

`SVGAnimationElement::CheckAnimationParameters()` ensures that keyTimes ends with 1, and when combined with `SVGAnimationElement::CalculateKeyTimesIndex()`, it guarantees that `to_percent` and `from_percent` will not be equal.

File third_party/blink/web_tests/svg/animations/animate-keytimes-with-keysplines-crash.html
File-level comment, Patchset 2:
Fredrik Söderquist . resolved

We could make this a WPT (and the expectation file shouldn't be needed).

YISI YU

I have added this test case to the WPT, so this file is no longer needed.

Line 7, Patchset 2: <animateMotion path="M0,0 L100,0 L100,100 Z" keyTimes="0;0.01;0.01" keyPoints="0;0.5;1"
Fredrik Söderquist . resolved

This should have a value of "1" at the end to be valid (with additional adjustments rto other attributes). (It should've been rejected by `SVGAnimationElement::CheckAnimationParameters`, but it seems to be missing this case.)

YISI YU

This is the key to resolving this issue. Please take a look at the detailed explanation in commit msg.

Line 18, Patchset 2: // Run the test for 10ms to make sure the animation is running for few frames.
Fredrik Söderquist . resolved

Could we try to write this as a test that (pauses and) seeks to the right point instead to trigger the same condition? That should be more predictable than this. (And could possibly be observable beyond the assertion.)

YISI YU

Done. This script is no longer needed.

Open in Gerrit

Related details

Attention is currently required from:
  • Fredrik Söderquist
  • Xianzhu Wang
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ideed8bdc02b77ba4acab5faa811df611097ef179
Gerrit-Change-Number: 7322721
Gerrit-PatchSet: 9
Gerrit-Owner: YISI YU <hello...@gmail.com>
Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
Gerrit-Reviewer: Xianzhu Wang <wangx...@chromium.org>
Gerrit-Reviewer: YISI YU <hello...@gmail.com>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Menard, Alexis <alexis...@intel.com>
Gerrit-CC: Olga Gerchikov <gerc...@microsoft.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Attention: Xianzhu Wang <wangx...@chromium.org>
Gerrit-Comment-Date: Wed, 14 Jan 2026 10:33:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Fredrik Söderquist <f...@opera.com>
Comment-In-Reply-To: YISI YU <hello...@gmail.com>
Comment-In-Reply-To: Xianzhu Wang <wangx...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Fredrik Söderquist (Gerrit)

unread,
8:27 AM (8 hours ago) 8:27 AM
to YISI YU, Xianzhu Wang, Chromium LUCI CQ, AyeAye, Menard, Alexis, chromium...@chromium.org, Dirk Schulze, Olga Gerchikov, Stephen Chenney, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, kouhe...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Xianzhu Wang and YISI YU

Fredrik Söderquist added 2 comments

Patchset-level comments
File-level comment, Patchset 12 (Latest):
Fredrik Söderquist . resolved

Code change LG, but I think we could do better on the test side

File third_party/blink/web_tests/external/wpt/svg/animations/animateMotion-spline-invalid-keyTimes-crash.html
Line 4, Patchset 12 (Latest):<title>When the calcMode of animateMotion is spline, if keyTimes does not end with 1, it should be rejected without causing a crash.</title>
Fredrik Söderquist . unresolved

I think we could make a more useful test now - one that verifies that the animation does not apply.

I think it could look something like this:
```
<!doctype html>
<title>keyTimes does not end with one, calcMode=spline</title>
<script src="/resources/testharness.js">
<script src="/resources/testharnessreport.js">
<svg>
<rect width="100" height="100" fill="green">
<animateMotion .../>
</rect>
</svg>
<script>
async_test(t => {
onload = t.step_func(() => {
requestAnimationFrame(t.step_func_done(() => {
const rect = document.querySelector("svg > rect");
assert_equals(rect.getCTM().e, 0, "motion path not applied");
}));
});
});
</script>
```
The path should probably be adjusted to have a non-zero initial value (I.e "M-100,-50 ..." or so).
Open in Gerrit

Related details

Attention is currently required from:
  • Xianzhu Wang
  • YISI YU
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ideed8bdc02b77ba4acab5faa811df611097ef179
    Gerrit-Change-Number: 7322721
    Gerrit-PatchSet: 12
    Gerrit-Owner: YISI YU <hello...@gmail.com>
    Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
    Gerrit-Reviewer: Xianzhu Wang <wangx...@chromium.org>
    Gerrit-Reviewer: YISI YU <hello...@gmail.com>
    Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
    Gerrit-CC: Menard, Alexis <alexis...@intel.com>
    Gerrit-CC: Olga Gerchikov <gerc...@microsoft.com>
    Gerrit-CC: Stephen Chenney <sche...@chromium.org>
    Gerrit-Attention: YISI YU <hello...@gmail.com>
    Gerrit-Attention: Xianzhu Wang <wangx...@chromium.org>
    Gerrit-Comment-Date: Wed, 14 Jan 2026 13:26:51 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    YISI YU (Gerrit)

    unread,
    11:16 AM (5 hours ago) 11:16 AM
    to Fredrik Söderquist, Xianzhu Wang, Chromium LUCI CQ, AyeAye, Menard, Alexis, chromium...@chromium.org, Dirk Schulze, Olga Gerchikov, Stephen Chenney, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, kouhe...@chromium.org, pdr+svgw...@chromium.org
    Attention needed from Fredrik Söderquist and Xianzhu Wang

    YISI YU voted and added 2 comments

    Votes added by YISI YU

    Auto-Submit+1

    2 comments

    Patchset-level comments
    File-level comment, Patchset 13 (Latest):
    YISI YU . resolved

    The change is ready, PTAL, thanks!

    File third_party/blink/web_tests/external/wpt/svg/animations/animateMotion-spline-invalid-keyTimes-crash.html
    Line 4, Patchset 12:<title>When the calcMode of animateMotion is spline, if keyTimes does not end with 1, it should be rejected without causing a crash.</title>
    Fredrik Söderquist . resolved

    I think we could make a more useful test now - one that verifies that the animation does not apply.

    I think it could look something like this:
    ```
    <!doctype html>
    <title>keyTimes does not end with one, calcMode=spline</title>
    <script src="/resources/testharness.js">
    <script src="/resources/testharnessreport.js">
    <svg>
    <rect width="100" height="100" fill="green">
    <animateMotion .../>
    </rect>
    </svg>
    <script>
    async_test(t => {
    onload = t.step_func(() => {
    requestAnimationFrame(t.step_func_done(() => {
    const rect = document.querySelector("svg > rect");
    assert_equals(rect.getCTM().e, 0, "motion path not applied");
    }));
    });
    });
    </script>
    ```
    The path should probably be adjusted to have a non-zero initial value (I.e "M-100,-50 ..." or so).
    YISI YU

    Thanks! I made a `smil_async_test` by looking at other SVG tests, and I put both the crash check and the apply validation in the same file.

    Before fix: the test won't pass. It crashed and failed when `DCHECK_IS_ON` was true. The animation still got applied when `DCHECK_IS_ON` was false.
    After fix: the test will pass. The spline animation won't be applied. `rect.getCMT().e` will always be zero.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Fredrik Söderquist
    • Xianzhu Wang
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ideed8bdc02b77ba4acab5faa811df611097ef179
      Gerrit-Change-Number: 7322721
      Gerrit-PatchSet: 13
      Gerrit-Owner: YISI YU <hello...@gmail.com>
      Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
      Gerrit-Reviewer: Xianzhu Wang <wangx...@chromium.org>
      Gerrit-Reviewer: YISI YU <hello...@gmail.com>
      Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
      Gerrit-CC: Menard, Alexis <alexis...@intel.com>
      Gerrit-CC: Olga Gerchikov <gerc...@microsoft.com>
      Gerrit-CC: Stephen Chenney <sche...@chromium.org>
      Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
      Gerrit-Attention: Xianzhu Wang <wangx...@chromium.org>
      Gerrit-Comment-Date: Wed, 14 Jan 2026 16:16:00 +0000
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Fredrik Söderquist (Gerrit)

      unread,
      11:48 AM (5 hours ago) 11:48 AM
      to YISI YU, Xianzhu Wang, Chromium LUCI CQ, AyeAye, Menard, Alexis, chromium...@chromium.org, Dirk Schulze, Olga Gerchikov, Stephen Chenney, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, kouhe...@chromium.org, pdr+svgw...@chromium.org
      Attention needed from Xianzhu Wang and YISI YU

      Fredrik Söderquist voted

      Code-Review+1
      Commit-Queue+2
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Xianzhu Wang
      • YISI YU
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ideed8bdc02b77ba4acab5faa811df611097ef179
      Gerrit-Change-Number: 7322721
      Gerrit-PatchSet: 13
      Gerrit-Owner: YISI YU <hello...@gmail.com>
      Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
      Gerrit-Reviewer: Xianzhu Wang <wangx...@chromium.org>
      Gerrit-Reviewer: YISI YU <hello...@gmail.com>
      Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
      Gerrit-CC: Menard, Alexis <alexis...@intel.com>
      Gerrit-CC: Olga Gerchikov <gerc...@microsoft.com>
      Gerrit-CC: Stephen Chenney <sche...@chromium.org>
      Gerrit-Attention: YISI YU <hello...@gmail.com>
      Gerrit-Attention: Xianzhu Wang <wangx...@chromium.org>
      Gerrit-Comment-Date: Wed, 14 Jan 2026 16:48:21 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Fredrik Söderquist (Gerrit)

      unread,
      11:49 AM (5 hours ago) 11:49 AM
      to YISI YU, Philip Rogers, Xianzhu Wang, Chromium LUCI CQ, AyeAye, Menard, Alexis, chromium...@chromium.org, Dirk Schulze, Olga Gerchikov, Stephen Chenney, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, kouhe...@chromium.org, pdr+svgw...@chromium.org
      Attention needed from Fredrik Söderquist, Philip Rogers, Xianzhu Wang and YISI YU

      Fredrik Söderquist added 1 comment

      Patchset-level comments
      Fredrik Söderquist . resolved

      Adding pdr for a second CR+1

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Fredrik Söderquist
      • Philip Rogers
      • Xianzhu Wang
      • YISI YU
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ideed8bdc02b77ba4acab5faa811df611097ef179
      Gerrit-Change-Number: 7322721
      Gerrit-PatchSet: 13
      Gerrit-Owner: YISI YU <hello...@gmail.com>
      Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
      Gerrit-Reviewer: Philip Rogers <p...@chromium.org>
      Gerrit-Reviewer: Xianzhu Wang <wangx...@chromium.org>
      Gerrit-Reviewer: YISI YU <hello...@gmail.com>
      Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
      Gerrit-CC: Menard, Alexis <alexis...@intel.com>
      Gerrit-CC: Olga Gerchikov <gerc...@microsoft.com>
      Gerrit-CC: Stephen Chenney <sche...@chromium.org>
      Gerrit-Attention: Philip Rogers <p...@chromium.org>
      Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
      Gerrit-Attention: YISI YU <hello...@gmail.com>
      Gerrit-Attention: Xianzhu Wang <wangx...@chromium.org>
      Gerrit-Comment-Date: Wed, 14 Jan 2026 16:49:23 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages