Skip to content

Commit

Permalink
add IntPtr to int conversion bounds check (dotnet#5011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed Feb 12, 2019
1 parent 966ce8b commit 74f24c9
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,11 @@ private void InterpretStoreElement(ILOpcode opcode)
index = indexItem.AsInt32();
break;
case StackValueKind.NativeInt:
index = (int)indexItem.AsNativeInt();
{
long value = (long)indexItem.AsNativeInt();
Debug.Assert(value >= int.MinValue && value <= int.MaxValue);
index = (int)value;
}
break;
default:
ThrowHelper.ThrowInvalidProgramException();
Expand Down Expand Up @@ -2224,7 +2228,11 @@ private void InterpretStoreElement(int token)
index = indexItem.AsInt32();
break;
case StackValueKind.NativeInt:
index = (int)indexItem.AsNativeInt();
{
long value = (long)indexItem.AsNativeInt();
Debug.Assert(value >= int.MinValue && value <= int.MaxValue);
index = (int)value;
}
break;
default:
ThrowHelper.ThrowInvalidProgramException();
Expand Down Expand Up @@ -2303,7 +2311,11 @@ private void InterpretLoadElement(ILOpcode opcode)
index = indexItem.AsInt32();
break;
case StackValueKind.NativeInt:
index = (int)indexItem.AsNativeInt();
{
long value = (long)indexItem.AsNativeInt();
Debug.Assert(value >= int.MinValue && value <= int.MaxValue);
index = (int)value;
}
break;
default:
ThrowHelper.ThrowInvalidProgramException();
Expand Down Expand Up @@ -2368,7 +2380,11 @@ private void InterpretLoadElement(int token)
index = indexItem.AsInt32();
break;
case StackValueKind.NativeInt:
index = (int)indexItem.AsNativeInt();
{
long value = (long)indexItem.AsNativeInt();
Debug.Assert(value >= int.MinValue && value <= int.MaxValue);
index = (int)value;
}
break;
default:
ThrowHelper.ThrowInvalidProgramException();
Expand Down

0 comments on commit 74f24c9

Please sign in to comment.