-
Notifications
You must be signed in to change notification settings - Fork 27
fix: use wrapping arithmetic for RCT transforms to prevent overflow panic #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
61b6d43 to
90926e8
Compare
veluca93
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should instead have the scalar implementations of the SIMD operations have wrapping semantics.
Benchmark @ 90926e8 |
…antics SIMD integer instructions wrap on overflow. The scalar fallback was using bare i32, which panics on overflow in debug builds. Changed scalar I32Vec from i32 to std::num::Wrapping<i32>. This makes +/-/* operators wrap automatically, matching SIMD behavior.
90926e8 to
0cdd96b
Compare
|
Updated to use This makes |
|
Can we do this with u32 too for consistency? Also, can you update the PR description? |
Summary
RCT (Reversible Color Transform) operations in modular decoding perform integer arithmetic that can overflow with certain input values. In debug mode, this causes a panic. In release mode, the behavior is undefined (though typically wraps on most platforms).
This PR:
wrapping_addandwrapping_submethods to theI32SimdVectraitFor SIMD types, integer addition/subtraction already wraps (this is inherent to SIMD integer ops), so the new methods simply delegate to
+/-. For scalari32, they call the standard library'swrapping_add/wrapping_sub.Test plan
🤖 Generated with Claude Code