Skip to content

Fix possible integer overflow#125500

Open
rustamque wants to merge 3 commits intodotnet:mainfrom
rustamque:fix-possible-integer-overflow
Open

Fix possible integer overflow#125500
rustamque wants to merge 3 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.

throw ADP.InvalidSourceBufferIndex(cbytes, dataIndex, nameof(dataIndex));
}

if (dataIndex < 0 || dataIndex > int.MaxValue)
Copy link
Member

Choose a reason for hiding this comment

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

dataIndex was just checked for being > int.MaxValue on the previous line, so it's definitely not here.

This shouldn't have an extra if block throwing a different exception type. The fix should just be to add a (ulong)dataIndex cast on L117. Same for the other version of this change below.

There should also be an included test that fails before the fix and passes after.

Thanks.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the review, Stephen! Working on your comments.

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.
@rustamque
Copy link
Author

@rustamque please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree company="Linux Verification Center"

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.

2 participants