Skip to content

Commit

Permalink
QJniArray: assert that source container is not too large
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Marc Mutz <[email protected]>
  • Loading branch information
vohi committed Jan 29, 2024
1 parent cc5251e commit 23fb1c5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/corelib/kernel/qjniarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class QJniArrayBase : public QJniObject
>
static auto fromContainer(Container &&container)
{
Q_ASSERT_X(size_t(container.size()) <= size_t((std::numeric_limits<size_type>::max)()),
"QJniArray::fromContainer", "Container is too large for a Java array");

using ElementType = typename std::remove_reference_t<Container>::value_type;
if constexpr (std::disjunction_v<std::is_same<ElementType, jobject>,
std::is_same<ElementType, QJniObject>>) {
Expand Down

0 comments on commit 23fb1c5

Please sign in to comment.