Skip to content

Fix for size check#3243

Open
shadidashmiz wants to merge 1 commit intodevelopfrom
amd/sdashmiz/ASANsizecheck
Open

Fix for size check#3243
shadidashmiz wants to merge 1 commit intodevelopfrom
amd/sdashmiz/ASANsizecheck

Conversation

@shadidashmiz
Copy link
Contributor

  • need to test

Motivation

Technical Details

JIRA ID

Test Plan

Test Result

Submission Checklist

- need to test

Signed-off-by: sdashmiz <shadi.dashmiz@amd.com>
@shadidashmiz shadidashmiz requested a review from a team as a code owner February 12, 2026 18:21
Copilot AI review requested due to automatic review settings February 12, 2026 18:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates HIP fat binary parsing to avoid out-of-bounds reads when identifying compressed/uncompressed/ELF code objects by adding explicit image-size bounds checks to the magic/header comparisons.

Changes:

  • Extend code-object type detection helpers to accept an image_size argument and guard memcmp calls with size checks.
  • Add an ELF magic (0x7F 'E' 'L' 'F') pre-check before reading ELF header fields.
  • Derive an image_size for file-mapped images and pass it through the detection logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +469 to +475
// Determine image size for bounds checking in magic string comparisons.
// For file-mapped images use the known file size; for direct-pointer images
// (compiler-embedded or user-provided) the size is not tracked, so use SIZE_MAX
// to allow the checks to proceed (caller is responsible for valid data).
const size_t image_size = (image_mapped_ && ufd_)
? (ufd_->fsize_ - foffset_)
: SIZE_MAX;
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

image_size falls back to SIZE_MAX when the buffer size is unknown, but this file doesn’t include a header that guarantees SIZE_MAX is defined on all toolchains. Also, other code in this repo typically uses std::numeric_limits<size_t>::max() (e.g. projects/clr/hipamd/src/hip_memory.cpp) instead of SIZE_MAX. Consider switching to std::numeric_limits<size_t>::max() (and including <limits>), or explicitly including the header that defines SIZE_MAX.

Copilot uses AI. Check for mistakes.
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