Skip to content

fix: avoid div by zero and underflow in pitch alloc size guess#226

Open
mesutoezdil wants to merge 1 commit into
Project-HAMi:mainfrom
mesutoezdil:fix/pitch-zero-width-crash
Open

fix: avoid div by zero and underflow in pitch alloc size guess#226
mesutoezdil wants to merge 1 commit into
Project-HAMi:mainfrom
mesutoezdil:fix/pitch-zero-width-crash

Conversation

@mesutoezdil

@mesutoezdil mesutoezdil commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Zero WidthInBytes underflows the size guess to SIZE_MAX, zero ElementSizeBytes divides by zero and crashes. This guards both to 0 before the guess is computed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of pitched memory allocation requests when the element size or width is zero.
    • Prevented invalid pitch calculations, ensuring memory sizing and out-of-memory tracking remain consistent for these edge cases.

@hami-robot
hami-robot Bot requested a review from archlitchi July 22, 2026 20:41
@hami-robot

hami-robot Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mesutoezdil
Once this PR has been reviewed and has the lgtm label, please assign archlitchi for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot
hami-robot Bot requested a review from chaunceyjiang July 22, 2026 20:41
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

cuMemAllocPitch_v2 now sets its pitch guess to zero when ElementSizeBytes or WidthInBytes is zero, changing bytesize and out-of-memory tracking for those cases.

Changes

Pitch validation

Layer / File(s) Summary
Zero-input pitch guard
src/cuda/memory.c
cuMemAllocPitch_v2 avoids division when either input dimension is zero and sets guess_pitch to 0.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: chaunceyjiang, archlitchi

Poem

A rabbit checked the pitch with care,
Found zero widths hiding there.
No divide now, the guess stays low,
Bytes track safely as they flow.
Hop, hop—edge cases go!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: guarding the pitch allocation size guess against division by zero and underflow.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hami-robot hami-robot Bot added the size/XS label Jul 22, 2026
@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jul 22, 2026
Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
@mesutoezdil
mesutoezdil force-pushed the fix/pitch-zero-width-crash branch from 4a85089 to 07de3e1 Compare July 22, 2026 20:42
@coderabbitai coderabbitai Bot removed the enhancement New feature or request label Jul 22, 2026
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.

1 participant