From 23fb1c50eecaed2f5a3ebfe95e72892c054e4414 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 Pick-to: 6.7 Change-Id: Ia0cbdbf098cf5b2c8ec50f0dd24dadf833bf40d0 Reviewed-by: Juha Vuolle Reviewed-by: Marc Mutz --- 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 f1346a99e6..22c1113f42 100644 --- a/src/corelib/kernel/qjniarray.h +++ b/src/corelib/kernel/qjniarray.h @@ -115,6 +115,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>) {