Skip to content

Commit 0e0d2d2

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-17745: zlib extension incorrectly handles object arguments
2 parents 9fb355b + 4b5c29e commit 0e0d2d2

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ PHP NEWS
5050
- Streams:
5151
. Fixed bug GH-17650 (realloc with size 0 in user_filters.c). (nielsdos)
5252

53+
- Zlib:
54+
. Fixed bug GH-17745 (zlib extension incorrectly handles object arguments).
55+
(nielsdos)
56+
5357
30 Jan 2025, PHP 8.4.4
5458

5559
- Core:

ext/zlib/tests/gh17745.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-17745 (zlib extension incorrectly handles object arguments)
3+
--EXTENSIONS--
4+
zlib
5+
--FILE--
6+
<?php
7+
$obj = new stdClass;
8+
$obj->level = 3;
9+
var_dump(deflate_init(ZLIB_ENCODING_RAW, $obj));
10+
11+
class Options {
12+
public int $level = 3;
13+
}
14+
var_dump(deflate_init(ZLIB_ENCODING_RAW, new Options));
15+
?>
16+
--EXPECT--
17+
object(DeflateContext)#2 (0) {
18+
}
19+
object(DeflateContext)#3 (0) {
20+
}

ext/zlib/zlib.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_
789789
zval *option_buffer;
790790

791791
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("dictionary"))) != NULL) {
792+
ZVAL_DEINDIRECT(option_buffer);
792793
ZVAL_DEREF(option_buffer);
793794
switch (Z_TYPE_P(option_buffer)) {
794795
case IS_STRING: {
@@ -869,6 +870,7 @@ PHP_FUNCTION(inflate_init)
869870
}
870871

871872
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
873+
ZVAL_DEINDIRECT(option_buffer);
872874
window = zval_get_long(option_buffer);
873875
}
874876
if (window < 8 || window > 15) {
@@ -1087,6 +1089,7 @@ PHP_FUNCTION(deflate_init)
10871089
}
10881090

10891091
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("level"))) != NULL) {
1092+
ZVAL_DEINDIRECT(option_buffer);
10901093
level = zval_get_long(option_buffer);
10911094
}
10921095
if (level < -1 || level > 9) {
@@ -1095,6 +1098,7 @@ PHP_FUNCTION(deflate_init)
10951098
}
10961099

10971100
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("memory"))) != NULL) {
1101+
ZVAL_DEINDIRECT(option_buffer);
10981102
memory = zval_get_long(option_buffer);
10991103
}
11001104
if (memory < 1 || memory > 9) {
@@ -1103,6 +1107,7 @@ PHP_FUNCTION(deflate_init)
11031107
}
11041108

11051109
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
1110+
ZVAL_DEINDIRECT(option_buffer);
11061111
window = zval_get_long(option_buffer);
11071112
}
11081113
if (window < 8 || window > 15) {
@@ -1111,6 +1116,7 @@ PHP_FUNCTION(deflate_init)
11111116
}
11121117

11131118
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("strategy"))) != NULL) {
1119+
ZVAL_DEINDIRECT(option_buffer);
11141120
strategy = zval_get_long(option_buffer);
11151121
}
11161122
switch (strategy) {

ext/zlib/zlib.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ function gzread($stream, int $length): string|false {}
270270
*/
271271
function gzgets($stream, ?int $length = null): string|false {}
272272

273-
function deflate_init(int $encoding, array $options = []): DeflateContext|false {}
273+
function deflate_init(int $encoding, array|object $options = []): DeflateContext|false {}
274274

275275
function deflate_add(DeflateContext $context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string|false {}
276276

277-
function inflate_init(int $encoding, array $options = []): InflateContext|false {}
277+
function inflate_init(int $encoding, array|object $options = []): InflateContext|false {}
278278

279279
function inflate_add(InflateContext $context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string|false {}
280280

ext/zlib/zlib_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)