Skip to content

Commit 614b22a

Browse files
committed
Add array size maximum to array_diff()
This silences some reports about the equivalence to array_merge()'s issue. However, this is different as no packed fill is used in this code, so it doesn't have the same bug that array_merge() had. Closes GH-21449.
1 parent 30b2d77 commit 614b22a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ PHP NEWS
134134
null destination). (David Carlier)
135135
. Fixed bug GH-13204 (glob() fails if square bracket is in current directory).
136136
(ndossche)
137+
. Add array size maximum to array_diff(). (ndossche)
137138

138139
- Streams:
139140
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream

ext/standard/array.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5741,7 +5741,7 @@ PHP_FUNCTION(array_diff)
57415741
{
57425742
zval *args;
57435743
uint32_t argc, i;
5744-
uint32_t num;
5744+
uint64_t num;
57455745
HashTable exclude;
57465746
zval *value;
57475747
zend_string *str, *tmp_str, *key;
@@ -5831,6 +5831,11 @@ PHP_FUNCTION(array_diff)
58315831
return;
58325832
}
58335833

5834+
if (UNEXPECTED(num >= HT_MAX_SIZE)) {
5835+
zend_throw_error(NULL, "The total number of elements must be lower than %u", HT_MAX_SIZE);
5836+
RETURN_THROWS();
5837+
}
5838+
58345839
ZVAL_NULL(&dummy);
58355840
/* create exclude map */
58365841
zend_hash_init(&exclude, num, NULL, NULL, 0);

0 commit comments

Comments
 (0)