Skip to content

Clamp AndroidFlingSpline.flingPosition to prevent array OOB - #29

Open
tonycoder-hub wants to merge 1 commit into
Tencent-TDS:ov/compose-1.6.1from
tonycoder-hub:cursor/flingposition-oob-d3c1
Open

Clamp AndroidFlingSpline.flingPosition to prevent array OOB#29
tonycoder-hub wants to merge 1 commit into
Tencent-TDS:ov/compose-1.6.1from
tonycoder-hub:cursor/flingposition-oob-d3c1

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Summary

  • Port the AndroidX compose-animation 1.7.0 clamp (9d47587, b/313685022) into this 1.6.1 tree.
  • A non-monotonic frame clock can feed a play time before animation start, so index = (NbSamples * time).toInt() goes negative and Kotlin Native throws ArrayIndexOutOfBoundsException (flingPosition caused array out of bounds exception #18).
  • Clamp time to [0, 1] before indexing. Same workaround that shipped upstream.

Test plan

  • AndroidFlingSplineTest#testClampedOutOfRangePosition — out-of-range inputs (-10, -1, -0.06, 1.5, 10) match the 0/1 endpoints and do not throw.

Fixes #18

Play time can be slightly below the animation start when the frame
clock is not monotonic. (NbSamples * time).toInt() then becomes
negative and SplinePositions[index] throws
ArrayIndexOutOfBoundsException (Tencent-TDS#18).

Port the published AndroidX compose-animation 1.7.0 workaround
(9d47587, b/313685022): coerce time into [0, 1] before indexing.

Test: AndroidFlingSplineTest#testClampedOutOfRangePosition

Co-authored-by: Tony Jin <407243179@qq.com>
@tencent-adm

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

flingPosition caused array out of bounds exception

3 participants