From 36c7a47b119ec00f11838d5cf507a91ec56bd71f Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Sun, 29 Oct 2023 17:59:44 +0100 Subject: [PATCH] Prevent `encode_variant` doing `memcpy` from `nullptr` (cherry picked from commit 210461f2ed386d072a7346f2f8d407d88c4ae9f9) --- core/io/marshalls.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 6ca7b0f831c..bbf3719ce39 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -1619,8 +1619,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const uint8_t *r = data.ptr(); - memcpy(buf, &r[0], datalen * datasize); - buf += datalen * datasize; + if (r) { + memcpy(buf, &r[0], datalen * datasize); + buf += datalen * datasize; + } } r_len += 4 + datalen * datasize;