Skip to content

Fix possible integer overflow#125500

Draft
rustamque wants to merge 4 commits intodotnet:mainfrom
rustamque:fix-possible-integer-overflow
Draft

Fix possible integer overflow#125500
rustamque wants to merge 4 commits intodotnet:mainfrom
rustamque:fix-possible-integer-overflow

Conversation

@rustamque
Copy link

If dataIndex is less than -2147483648, InvalidSourceBufferIndex will not be thrown. In this case, int ndataIndex = (int)dataIndex; assigns ndataIndex the truncated value of dataIndex.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 12, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @SamMonoRT, @dotnet/efteam
See info in area-owners.md if you want to be subscribed.

Rustam Safarov added 2 commits March 12, 2026 20:03
Used a (ulong) cast to simultaneously check for negative values and values greater than int.MaxValue. This prevents potential out-of-bounds reads with negative indices like Int64.MinValue while preserving the original exception type.
@AndriySvyryd AndriySvyryd requested a review from Copilot March 13, 2026 19:46
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

Fixes integer overflow when dataIndex is a large negative long value by casting to ulong before comparison, ensuring negative values are caught.

Changes:

  • Cast dataIndex to ulong before comparing to int.MaxValue in GetBytes and GetChars
  • Added tests for Int64.MinValue as dataIndex

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
DataRecordInternal.cs Cast dataIndex to ulong to catch negative values
DataRecordInternalTest.cs Tests for negative dataIndex overflow scenario

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Andriy Svyryd <AndriySvyryd@users.noreply.github.com>
@rustamque
Copy link
Author

Should i push this changes to other branches (release/*)?

@rustamque rustamque marked this pull request as draft March 16, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Data community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants