From 6fe0fd0bf562b1e1429075911257ad160997214f Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Mon, 2 Feb 2026 10:57:39 +0530 Subject: [PATCH 1/8] standard: Validate sort_type argument in array_unique() --- ext/standard/array.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ext/standard/array.c b/ext/standard/array.c index f8dd7d891dd39..1e811c3b18c4e 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4863,6 +4863,18 @@ PHP_FUNCTION(array_unique) return; } + if (sort_type != PHP_SORT_REGULAR && + sort_type != PHP_SORT_NUMERIC && + sort_type != PHP_SORT_STRING && + sort_type != PHP_SORT_LOCALE_STRING) { + + zend_argument_value_error( + 2, + "must be one of PHP_SORT_REGULAR, PHP_SORT_NUMERIC, PHP_SORT_STRING, or PHP_SORT_LOCALE_STRING" + ); + RETURN_THROWS(); + } + if (sort_type == PHP_SORT_STRING) { HashTable seen; zend_long num_key; From 747ddc4bd6d839d5e564027e05c0b1639992f01e Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Mon, 2 Feb 2026 10:59:20 +0530 Subject: [PATCH 2/8] standard: Validate sort_type argument in array_unique() --- .../array/array_unique_invalid_sort_type.phpt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ext/standard/tests/array/array_unique_invalid_sort_type.phpt diff --git a/ext/standard/tests/array/array_unique_invalid_sort_type.phpt b/ext/standard/tests/array/array_unique_invalid_sort_type.phpt new file mode 100644 index 0000000000000..e3907f309a456 --- /dev/null +++ b/ext/standard/tests/array/array_unique_invalid_sort_type.phpt @@ -0,0 +1,19 @@ +--TEST-- +array_unique() throws ValueError on invalid sort_type +--FILE-- +getMessage(), PHP_EOL; +} + +try { + array_unique([1, 2, 3], -1); +} catch (ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +?> +--EXPECT-- +array_unique(): Argument #2 ($flags) must be one of PHP_SORT_REGULAR, PHP_SORT_NUMERIC, PHP_SORT_STRING, or PHP_SORT_LOCALE_STRING +array_unique(): Argument #2 ($flags) must be one of PHP_SORT_REGULAR, PHP_SORT_NUMERIC, PHP_SORT_STRING, or PHP_SORT_LOCALE_STRING From 0ac0713dd639e8e56e2f004cce5a50019013033b Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Mon, 2 Feb 2026 11:00:12 +0530 Subject: [PATCH 3/8] standard: Validate sort_type argument in array_unique() --- ext/standard/tests/array/array_unique_invalid_sort_type.phpt | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/standard/tests/array/array_unique_invalid_sort_type.phpt b/ext/standard/tests/array/array_unique_invalid_sort_type.phpt index e3907f309a456..e1edd0ea1a7c0 100644 --- a/ext/standard/tests/array/array_unique_invalid_sort_type.phpt +++ b/ext/standard/tests/array/array_unique_invalid_sort_type.phpt @@ -17,3 +17,4 @@ try { --EXPECT-- array_unique(): Argument #2 ($flags) must be one of PHP_SORT_REGULAR, PHP_SORT_NUMERIC, PHP_SORT_STRING, or PHP_SORT_LOCALE_STRING array_unique(): Argument #2 ($flags) must be one of PHP_SORT_REGULAR, PHP_SORT_NUMERIC, PHP_SORT_STRING, or PHP_SORT_LOCALE_STRING + From d614a2f729ef32b9275f193b6c4ed85a2c798a93 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Mon, 2 Feb 2026 11:36:25 +0530 Subject: [PATCH 4/8] standard: Validate sort_type argument in array_unique() --- ext/standard/array.c | 2 +- ext/standard/tests/array/array_unique_invalid_sort_type.phpt | 4 ++-- ext/standard/tests/array/gh20043.phpt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index 1e811c3b18c4e..6e4d70a93217e 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4870,7 +4870,7 @@ PHP_FUNCTION(array_unique) zend_argument_value_error( 2, - "must be one of PHP_SORT_REGULAR, PHP_SORT_NUMERIC, PHP_SORT_STRING, or PHP_SORT_LOCALE_STRING" + "must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING" ); RETURN_THROWS(); } diff --git a/ext/standard/tests/array/array_unique_invalid_sort_type.phpt b/ext/standard/tests/array/array_unique_invalid_sort_type.phpt index e1edd0ea1a7c0..e431b66700ef1 100644 --- a/ext/standard/tests/array/array_unique_invalid_sort_type.phpt +++ b/ext/standard/tests/array/array_unique_invalid_sort_type.phpt @@ -15,6 +15,6 @@ try { } ?> --EXPECT-- -array_unique(): Argument #2 ($flags) must be one of PHP_SORT_REGULAR, PHP_SORT_NUMERIC, PHP_SORT_STRING, or PHP_SORT_LOCALE_STRING -array_unique(): Argument #2 ($flags) must be one of PHP_SORT_REGULAR, PHP_SORT_NUMERIC, PHP_SORT_STRING, or PHP_SORT_LOCALE_STRING +array_unique(): Argument #2 ($flags) must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING +array_unique(): Argument #2 ($flags) must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING diff --git a/ext/standard/tests/array/gh20043.phpt b/ext/standard/tests/array/gh20043.phpt index d5c7e06417f18..67b925947e0bc 100644 --- a/ext/standard/tests/array/gh20043.phpt +++ b/ext/standard/tests/array/gh20043.phpt @@ -3,7 +3,7 @@ GH-20043 (array_unique assertion failure with RC1 array causing an exception on --FILE-- getMessage(); } From fa834c9106c610fc81f3e6fe4edfebd0b3a345c0 Mon Sep 17 00:00:00 2001 From: Arshid Date: Mon, 2 Feb 2026 21:10:01 +0530 Subject: [PATCH 5/8] Update ext/standard/array.c Co-authored-by: Ilija Tovilo --- ext/standard/array.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index 6e4d70a93217e..290a1f38d0ea4 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4863,10 +4863,10 @@ PHP_FUNCTION(array_unique) return; } - if (sort_type != PHP_SORT_REGULAR && - sort_type != PHP_SORT_NUMERIC && - sort_type != PHP_SORT_STRING && - sort_type != PHP_SORT_LOCALE_STRING) { + if (sort_type != PHP_SORT_REGULAR + && sort_type != PHP_SORT_NUMERIC + && sort_type != PHP_SORT_STRING + && sort_type != PHP_SORT_LOCALE_STRING) { zend_argument_value_error( 2, From d2e1af2e44a0be85c738337cc6e83c29da281c08 Mon Sep 17 00:00:00 2001 From: Arshid Date: Mon, 2 Feb 2026 21:10:13 +0530 Subject: [PATCH 6/8] Update ext/standard/array.c Co-authored-by: Ilija Tovilo --- ext/standard/array.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index 290a1f38d0ea4..df33bc4ec0a73 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4869,9 +4869,7 @@ PHP_FUNCTION(array_unique) && sort_type != PHP_SORT_LOCALE_STRING) { zend_argument_value_error( - 2, - "must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING" - ); + 2, "must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING"); RETURN_THROWS(); } From f2d0acad817a8702623b7576c81baae77c2ed3c9 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Mon, 2 Feb 2026 21:11:59 +0530 Subject: [PATCH 7/8] array unique --- ext/standard/array.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/standard/array.c b/ext/standard/array.c index 290a1f38d0ea4..d792b2afbd9e1 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4866,6 +4866,7 @@ PHP_FUNCTION(array_unique) if (sort_type != PHP_SORT_REGULAR && sort_type != PHP_SORT_NUMERIC && sort_type != PHP_SORT_STRING + && sort_type != PHP_SORT_FLAG_CASE && sort_type != PHP_SORT_LOCALE_STRING) { zend_argument_value_error( From 3e96bfe8c92789e5307de84d4bf0fc7882866352 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Mon, 2 Feb 2026 21:27:19 +0530 Subject: [PATCH 8/8] array unique --- ext/standard/array.c | 11 ++++++----- ext/standard/tests/array/gh20043.phpt | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index d792b2afbd9e1..c24ac02223683 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4863,11 +4863,12 @@ PHP_FUNCTION(array_unique) return; } - if (sort_type != PHP_SORT_REGULAR - && sort_type != PHP_SORT_NUMERIC - && sort_type != PHP_SORT_STRING - && sort_type != PHP_SORT_FLAG_CASE - && sort_type != PHP_SORT_LOCALE_STRING) { + zend_long base_sort = sort_type & ~PHP_SORT_FLAG_CASE; + + if (base_sort != PHP_SORT_REGULAR + && base_sort != PHP_SORT_NUMERIC + && base_sort != PHP_SORT_STRING + && base_sort != PHP_SORT_LOCALE_STRING) { zend_argument_value_error( 2, diff --git a/ext/standard/tests/array/gh20043.phpt b/ext/standard/tests/array/gh20043.phpt index 67b925947e0bc..d5c7e06417f18 100644 --- a/ext/standard/tests/array/gh20043.phpt +++ b/ext/standard/tests/array/gh20043.phpt @@ -3,7 +3,7 @@ GH-20043 (array_unique assertion failure with RC1 array causing an exception on --FILE-- getMessage(); }