Conversation
|
Tagging subscribers to this area: @SamMonoRT, @dotnet/efteam |
| throw ADP.InvalidSourceBufferIndex(cbytes, dataIndex, nameof(dataIndex)); | ||
| } | ||
|
|
||
| if (dataIndex < 0 || dataIndex > int.MaxValue) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thanks for the review, Stephen! Working on your comments.
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.
@dotnet-policy-service agree company="Linux Verification Center" |
If
dataIndexis less than-2147483648,InvalidSourceBufferIndexwill not be thrown. In this case,int ndataIndex = (int)dataIndex;assignsndataIndexthe truncated value ofdataIndex.Found by Linux Verification Center (linuxtesting.org) with SVACE.