diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-11-08 13:33:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-08 13:33:07 +0100 |
commit | 63559f2c80e29231596aec9cee4de79139584373 (patch) | |
tree | c773f7ddc67d645daa13d62b58c96c98301bbff6 | |
parent | 0b0f7fa9ef5ad58050bcb502fd4f599a94856fd5 (diff) | |
parent | 9ed84172713efba8fcb38a83aed3205b70758588 (diff) |
Merge pull request #54186 from miraz12/fix-packedByteArray-memcpy-crash
-rw-r--r-- | core/variant/variant_call.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index f710a1267f..c3fe443456 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -752,8 +752,9 @@ struct _VariantCall { static PackedInt32Array func_PackedByteArray_decode_s32_array(PackedByteArray *p_instance) { uint64_t size = p_instance->size(); - const uint8_t *r = p_instance->ptr(); PackedInt32Array dest; + ERR_FAIL_COND_V_MSG(size < sizeof(int32_t), dest, "Size didn't match array of size int32_t, maybe you are trying to convert to the wrong type?"); + const uint8_t *r = p_instance->ptr(); dest.resize(size / sizeof(int32_t)); memcpy(dest.ptrw(), r, size); return dest; @@ -761,8 +762,9 @@ struct _VariantCall { static PackedInt64Array func_PackedByteArray_decode_s64_array(PackedByteArray *p_instance) { uint64_t size = p_instance->size(); - const uint8_t *r = p_instance->ptr(); PackedInt64Array dest; + ERR_FAIL_COND_V_MSG(size < sizeof(int64_t), dest, "Size didn't match array of size int64_t, maybe you are trying to convert to the wrong type?"); + const uint8_t *r = p_instance->ptr(); dest.resize(size / sizeof(int64_t)); memcpy(dest.ptrw(), r, size); return dest; @@ -770,8 +772,9 @@ struct _VariantCall { static PackedFloat32Array func_PackedByteArray_decode_float_array(PackedByteArray *p_instance) { uint64_t size = p_instance->size(); - const uint8_t *r = p_instance->ptr(); PackedFloat32Array dest; + ERR_FAIL_COND_V_MSG(size < sizeof(float), dest, "Size didn't match array of size float, maybe you are trying to convert to the wrong type?"); + const uint8_t *r = p_instance->ptr(); dest.resize(size / sizeof(float)); memcpy(dest.ptrw(), r, size); return dest; @@ -779,8 +782,9 @@ struct _VariantCall { static PackedFloat64Array func_PackedByteArray_decode_double_array(PackedByteArray *p_instance) { uint64_t size = p_instance->size(); - const uint8_t *r = p_instance->ptr(); PackedFloat64Array dest; + ERR_FAIL_COND_V_MSG(size < sizeof(double), dest, "Size didn't match array of size double, maybe you are trying to convert to the wrong type?"); + const uint8_t *r = p_instance->ptr(); dest.resize(size / sizeof(double)); memcpy(dest.ptrw(), r, size); return dest; |