From ee895907f88e7af85ea197df47a9494217356c87 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 22 Jan 2024 16:08:27 +0100 Subject: [PATCH] QJniArray: assert that source container is not too large Java still only can handle arrays of at most 2^31 entries, and the JNI API for working with arrays is using types that are essentially int. Assert that the container passed in is not larger than that. Found during API review. Task-number: QTBUG-119952 Change-Id: Ia0cbdbf098cf5b2c8ec50f0dd24dadf833bf40d0 Reviewed-by: Juha Vuolle Reviewed-by: Marc Mutz (cherry picked from commit 23fb1c50eecaed2f5a3ebfe95e72892c054e4414) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qjniarray.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/corelib/kernel/qjniarray.h b/src/corelib/kernel/qjniarray.h index 9b3e91b7e06..bf09e9db63a 100644 --- a/src/corelib/kernel/qjniarray.h +++ b/src/corelib/kernel/qjniarray.h @@ -105,6 +105,9 @@ public: > static auto fromContainer(Container &&container) { + Q_ASSERT_X(size_t(container.size()) <= size_t((std::numeric_limits::max)()), + "QJniArray::fromContainer", "Container is too large for a Java array"); + using ElementType = typename std::remove_reference_t::value_type; if constexpr (std::disjunction_v, std::is_same>) {