Skip to content
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

Fix possible itemsize overflows in usm_ndarray from-pointer constructors #2003

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

ndgrigorian
Copy link
Collaborator

@ndgrigorian ndgrigorian commented Feb 20, 2025

C-API functions which make a usm_ndarray from a pointer (UsmNDArray_MakeSimpleFromPtr and UsmNDArray_MakeFromPtr) take an integral typenum argument

If this argument is invalid, the itemsize declared in the functions would be returned from type_bytesize as -1 and could potentially overflow

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?
  • If this PR is a work in progress, are you opening the PR as a draft?

When a bad typenum is passed to functions which make usm_ndarrays from pointers, there was a possible underflow, as itemsize was declared size_t

Instead declare itemsize as int and cast to size_t when needed (as itemsize should always fit in int)
@ndgrigorian ndgrigorian force-pushed the fix-possible-overflow-itemsize branch from 2a683e9 to 292bc2a Compare February 20, 2025 06:14
Copy link

github-actions bot commented Feb 20, 2025

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310h93fe807_527 ran successfully.
Passed: 894
Failed: 2
Skipped: 118

@coveralls
Copy link
Collaborator

coveralls commented Feb 20, 2025

Coverage Status

coverage: 88.233% (+0.009%) from 88.224%
when pulling ba7c090 on fix-possible-overflow-itemsize
into a34686f on master.

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310h93fe807_527 ran successfully.
Passed: 893
Failed: 3
Skipped: 118

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310h93fe807_530 ran successfully.
Passed: 895
Failed: 1
Skipped: 118

Copy link
Collaborator

@antonwolfy antonwolfy left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @ndgrigorian

@ndgrigorian ndgrigorian merged commit a38e0f2 into master Feb 21, 2025
76 checks passed
@ndgrigorian ndgrigorian deleted the fix-possible-overflow-itemsize branch February 21, 2025 15:56
ndgrigorian added a commit that referenced this pull request Feb 21, 2025
@ndgrigorian ndgrigorian mentioned this pull request Feb 21, 2025
8 tasks
ndgrigorian added a commit that referenced this pull request Feb 21, 2025
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.

3 participants