Fix some range checks appeared to be incorrect when index > array.size

This commit is contained in:
Svyatoslav Scherbina
2018-08-31 10:52:08 +03:00
committed by SvyatoslavScherbina
parent 307e4fc3fd
commit 5aaf075af8
+4 -4
View File
@@ -38,8 +38,8 @@ inline void copyImpl(KConstRef thiz, KInt fromIndex,
const ArrayHeader* array = thiz->array(); const ArrayHeader* array = thiz->array();
ArrayHeader* destinationArray = destination->array(); ArrayHeader* destinationArray = destination->array();
if (count < 0 || if (count < 0 ||
fromIndex < 0 || count > array->count_ - fromIndex || fromIndex < 0 || static_cast<uint32_t>(count) + fromIndex > array->count_ ||
toIndex < 0 || count > destinationArray->count_ - toIndex) { toIndex < 0 || static_cast<uint32_t>(count) + toIndex > destinationArray->count_) {
ThrowArrayIndexOutOfBoundsException(); ThrowArrayIndexOutOfBoundsException();
} }
mutabilityCheck(destination); mutabilityCheck(destination);
@@ -96,8 +96,8 @@ void Kotlin_Array_copyImpl(KConstRef thiz, KInt fromIndex,
const ArrayHeader* array = thiz->array(); const ArrayHeader* array = thiz->array();
ArrayHeader* destinationArray = destination->array(); ArrayHeader* destinationArray = destination->array();
if (count < 0 || if (count < 0 ||
fromIndex < 0 || count > array->count_ - fromIndex || fromIndex < 0 || static_cast<uint32_t>(count) + fromIndex > array->count_ ||
toIndex < 0 || count > destinationArray->count_ - toIndex) { toIndex < 0 || static_cast<uint32_t>(count)+ toIndex > destinationArray->count_) {
ThrowArrayIndexOutOfBoundsException(); ThrowArrayIndexOutOfBoundsException();
} }
mutabilityCheck(destination); mutabilityCheck(destination);