Skip to content

Fix signed integer overflow in MakeKernelParams8bit - #373

Closed
wangw-1991 wants to merge 2 commits into
google:masterfrom
wangw-1991:fix_integer_overflow
Closed

Fix signed integer overflow in MakeKernelParams8bit#373
wangw-1991 wants to merge 2 commits into
google:masterfrom
wangw-1991:fix_integer_overflow

Conversation

@wangw-1991

@wangw-1991 wangw-1991 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Compute prod_zp_depth via uint32_t casts so the intended wraparound is well-defined rather than UB. Overflow checks on the surrounding offset/pointer computations are left untouched.

See chromium issue: https://issues.chromium.org/issues/526978330 and https://issues.chromium.org/issues/520870343

@wangw-1991

Copy link
Copy Markdown
Contributor Author

Hi, @reillyeon. Can you help take a look or find a suitable reviewer? Thanks.

Comment thread ruy/kernel_common.h Outdated
int start_row, int start_col, int end_row,
int end_col, Mat<DstScalar>* dst,
KernelParams8bit<LhsCols, RhsCols>* params) {
RUY_NO_SANITIZE_INTEGER_OVERFLOW void MakeKernelParams8bit(

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.

This seems wrong because this function is computing buffer offsets which should be checked for overflow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, you're right that a function-level overflow suppression is wrong here. The UBSan report actually pointed at prod_zp_depth = lhs.zero_point * rhs.zero_point * depth . That value is a numeric accumulator constant, not a buffer offset, and it intentionally wraps to match the two's-complement arithmetic of the asm kernels.

So instead of exempting the whole function, I dropped the annotation and now compute prod_zp_depth with uint32_t casts so the wrap is well-defined. All the offset/pointer arithmetic keeps its overflow checks.

@wangw-1991 wangw-1991 changed the title Introduce RUY_NO_SANITIZE_INTEGER_OVERFLOW macro Fix signed integer overflow in MakeKernelParams8bit Jul 21, 2026
@wangw-1991
wangw-1991 requested a review from reillyeon July 21, 2026 08:07

@reillyeon reillyeon 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.

I'm still working on finding a reviewer with permission to merge this.

@wangw-1991

Copy link
Copy Markdown
Contributor Author

OK, thanks for the review.

@snnn snnn added the cla: yes label Jul 22, 2026
@snnn

snnn commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

I am sending the PR to Google's engineers to review.

@wangw-1991
wangw-1991 deleted the fix_integer_overflow branch July 24, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants