[packages/php/PHP_7_3] rel 22: session upload progress never destroys or overwrites undecodable sessions
arekm
arekm at pld-linux.org
Fri Oct 23 16:28:25 CEST 2026
commit 6c782c7c03b1e221052436887e5e8360e3aae673
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Fri Oct 23 16:27:38 2026 +0200
rel 22: session upload progress never destroys or overwrites undecodable sessions
php-cve-2026-109618-session.patch | 425 +++++++++++++++-----------------------
php.spec | 2 +-
2 files changed, 168 insertions(+), 259 deletions(-)
---
diff --git a/php.spec b/php.spec
index 8a49e2e..88388ed 100644
--- a/php.spec
+++ b/php.spec
@@ -155,7 +155,7 @@ Summary(ru.UTF-8): PHP Версии 7 - язык препроцессирова
Summary(uk.UTF-8): PHP Версії 7 - мова препроцесування HTML-файлів, виконувана на сервері
Name: %{orgname}%{php_suffix}
Version: 7.3.33
-Release: 21
+Release: 22
Epoch: 4
# All files licensed under PHP version 3.01, except
# Zend is licensed under Zend
diff --git a/php-cve-2026-109618-session.patch b/php-cve-2026-109618-session.patch
index f147bb6..9eee9f1 100644
--- a/php-cve-2026-109618-session.patch
+++ b/php-cve-2026-109618-session.patch
@@ -5,7 +5,7 @@ The minimal EOL fix for CVE-2026-109618 turns session upload progress off.
This is the session part of the PHP 8.2 fix instead (same code in master):
the progress handler runs before RINIT and now decodes the session with every
object kept as __PHP_Incomplete_Class (no autoload, unserialize_callback_func,
-__wakeup()), writing C: payloads back verbatim.
+__wakeup()).
Backported to 7.3: no enums or __unserialize() here, no request_parse_body()
guard (7.3 parses POST before RINIT only), OOM unwinding parts left out, tests
@@ -13,6 +13,13 @@ use a proc_open() command string and display_startup_errors. Added: progress is
skipped for third-party session serializers (igbinary, msgpack), which still
resolve classes and call __wakeup() while decoding.
+Changed from 8.2: a session that cannot be decoded this way is left alone and
+its progress is not recorded, where 8.2 destroys it. This includes every
+Serializable (C:) object, which 8.2 writes back verbatim: the values that
+Serializable::serialize() nests through serialize() share the back-reference
+numbering of the session, so without the class the references after such an
+object resolve to other values or to none.
+
Origin: backport, https://github.com/php/php-src/commit/3584a98bda0f
Bug: https://github.com/php/php-src/security/advisories/GHSA-w8hw-w9fx-j79w
---
@@ -30,7 +37,7 @@ index 0119a79f..eee67c66 100644
typedef php_ps_globals zend_ps_globals;
diff --git a/ext/session/session.c b/ext/session/session.c
-index c23baf47..25085229 100644
+index 5910861e..de55e947 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -120,6 +120,7 @@ static inline void php_rinit_session_globals(void) /* {{{ */
@@ -41,7 +48,31 @@ index c23baf47..25085229 100644
ZVAL_UNDEF(&PS(http_session_vars));
}
/* }}} */
-@@ -835,13 +836,34 @@ PHP_INI_END()
+@@ -249,6 +250,10 @@ static int php_session_decode(zend_string *data) /* {{{ */
+ return FAILURE;
+ }
+ if (PS(serializer)->decode(ZSTR_VAL(data), ZSTR_LEN(data)) == FAILURE) {
++ if (PS(in_rfc1867_update)) {
++ /* the request itself may still decode the data, see php_session_unserialize_init() */
++ return FAILURE;
++ }
+ php_session_destroy();
+ php_session_track_init();
+ php_error_docref(NULL, E_WARNING, "Failed to decode session object. Session has been destroyed");
+@@ -454,7 +459,11 @@ static int php_session_initialize(void) /* {{{ */
+ if (PS(lazy_write)) {
+ PS(session_vars) = zend_string_copy(val);
+ }
+- php_session_decode(val);
++ if (php_session_decode(val) == FAILURE && PS(in_rfc1867_update)) {
++ zend_string_release_ex(val, 0);
++ php_session_abort();
++ return FAILURE;
++ }
+ zend_string_release_ex(val, 0);
+ }
+ return SUCCESS;
+@@ -835,6 +844,20 @@ PHP_INI_END()
/* ***************
* Serializers *
*************** */
@@ -49,7 +80,8 @@ index c23baf47..25085229 100644
+ * re-encodes the session during request startup, before RINIT, when no user
+ * code may run. Objects are then kept as __PHP_Incomplete_Class: no
+ * autoloading, no unserialize_callback_func, no __wakeup(), and they are
-+ * written back unchanged. */
++ * written back unchanged. Data that cannot be decoded that way (Serializable
++ * objects) is left alone: the progress is not recorded. */
+static void php_session_unserialize_init(php_unserialize_data_t *var_hash)
+{
+ PHP_VAR_UNSERIALIZE_INIT(*var_hash);
@@ -57,27 +89,11 @@ index c23baf47..25085229 100644
+ php_var_unserialize_set_incomplete_classes_only(*var_hash, 1);
+ }
+}
-+
-+static void php_session_serialize_init(php_serialize_data_t *var_hash)
-+{
-+ PHP_VAR_SERIALIZE_INIT(*var_hash);
-+ if (PS(in_rfc1867_update)) {
-+ php_var_serialize_set_incomplete_classes_only(*var_hash, 1);
-+ }
-+}
+
PS_SERIALIZER_ENCODE_FUNC(php_serialize) /* {{{ */
{
smart_str buf = {0};
- php_serialize_data_t var_hash;
-
- IF_SESSION_VARS() {
-- PHP_VAR_SERIALIZE_INIT(var_hash);
-+ php_session_serialize_init(&var_hash);
- php_var_serialize(&buf, Z_REFVAL(PS(http_session_vars)), &var_hash);
- PHP_VAR_SERIALIZE_DESTROY(var_hash);
- }
-@@ -858,7 +880,7 @@ PS_SERIALIZER_DECODE_FUNC(php_serialize) /* {{{ */
+@@ -858,13 +881,18 @@ PS_SERIALIZER_DECODE_FUNC(php_serialize) /* {{{ */
zend_string *var_name = zend_string_init("_SESSION", sizeof("_SESSION") - 1, 0);
ZVAL_NULL(&session_vars);
@@ -86,16 +102,18 @@ index c23baf47..25085229 100644
result = php_var_unserialize(
&session_vars, (const unsigned char **)&val, (const unsigned char *)endptr, &var_hash);
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
-@@ -891,7 +913,7 @@ PS_SERIALIZER_ENCODE_FUNC(php_binary) /* {{{ */
- php_serialize_data_t var_hash;
- PS_ENCODE_VARS;
-
-- PHP_VAR_SERIALIZE_INIT(var_hash);
-+ php_session_serialize_init(&var_hash);
+ if (!result) {
+ zval_ptr_dtor(&session_vars);
+ ZVAL_NULL(&session_vars);
++ if (PS(in_rfc1867_update)) {
++ /* the empty session would be written back over the data */
++ zend_string_release_ex(var_name, 0);
++ return FAILURE;
++ }
+ }
- PS_ENCODE_LOOP(
- if (ZSTR_LEN(key) > PS_BIN_MAX) continue;
-@@ -916,7 +938,7 @@ PS_SERIALIZER_DECODE_FUNC(php_binary) /* {{{ */
+ if (!Z_ISUNDEF(PS(http_session_vars))) {
+@@ -916,7 +944,7 @@ PS_SERIALIZER_DECODE_FUNC(php_binary) /* {{{ */
php_unserialize_data_t var_hash;
zval *current, rv;
@@ -104,16 +122,7 @@ index c23baf47..25085229 100644
for (p = val; p < endptr; ) {
namelen = ((unsigned char)(*p)) & (~PS_BIN_UNDEF);
-@@ -957,7 +979,7 @@ PS_SERIALIZER_ENCODE_FUNC(php) /* {{{ */
- php_serialize_data_t var_hash;
- PS_ENCODE_VARS;
-
-- PHP_VAR_SERIALIZE_INIT(var_hash);
-+ php_session_serialize_init(&var_hash);
-
- PS_ENCODE_LOOP(
- smart_str_appendl(&buf, ZSTR_VAL(key), ZSTR_LEN(key));
-@@ -987,7 +1009,7 @@ PS_SERIALIZER_DECODE_FUNC(php) /* {{{ */
+@@ -987,7 +1015,7 @@ PS_SERIALIZER_DECODE_FUNC(php) /* {{{ */
php_unserialize_data_t var_hash;
zval *current, rv;
@@ -122,7 +131,7 @@ index c23baf47..25085229 100644
p = val;
-@@ -2921,6 +2943,7 @@ static PHP_GINIT_FUNCTION(ps) /* {{{ */
+@@ -2920,6 +2948,7 @@ static PHP_GINIT_FUNCTION(ps) /* {{{ */
ps_globals->mod_user_implemented = 0;
ps_globals->mod_user_is_open = 0;
ps_globals->session_vars = NULL;
@@ -130,7 +139,7 @@ index c23baf47..25085229 100644
ps_globals->set_handler = 0;
for (i = 0; i < PS_NUM_APIS; i++) {
ZVAL_UNDEF(&ps_globals->mod_user_names.names[i]);
-@@ -3127,8 +3150,12 @@ static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, i
+@@ -3126,8 +3155,12 @@ static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, i
progress->next_update = Z_LVAL_P(progress->post_bytes_processed) + progress->update_step;
}
@@ -145,7 +154,7 @@ index c23baf47..25085229 100644
IF_SESSION_VARS() {
zval *sess_var = Z_REFVAL(PS(http_session_vars));
SEPARATE_ARRAY(sess_var);
-@@ -3138,20 +3165,33 @@ static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, i
+@@ -3137,20 +3170,33 @@ static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, i
zend_hash_update(Z_ARRVAL_P(sess_var), progress->key.s, &progress->data);
}
php_session_flush(1);
@@ -181,7 +190,7 @@ index c23baf47..25085229 100644
static int php_session_rfc1867_callback(unsigned int event, void *event_data, void **extra) /* {{{ */
{
php_session_rfc1867_progress *progress;
-@@ -3160,7 +3200,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
+@@ -3159,7 +3205,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
if (php_session_rfc1867_orig_callback) {
retval = php_session_rfc1867_orig_callback(event, event_data, extra);
}
@@ -190,7 +199,7 @@ index c23baf47..25085229 100644
return retval;
}
-@@ -3169,6 +3209,10 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
+@@ -3168,6 +3214,10 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
switch(event) {
case MULTIPART_EVENT_START: {
multipart_event_start *data = (multipart_event_start *) event_data;
@@ -201,7 +210,7 @@ index c23baf47..25085229 100644
progress = ecalloc(1, sizeof(php_session_rfc1867_progress));
progress->content_length = data->content_length;
progress->sname_len = strlen(PS(session_name));
-@@ -3326,6 +3370,11 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
+@@ -3325,6 +3375,11 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
efree(progress);
progress = NULL;
PS(rfc1867_progress) = NULL;
@@ -215,12 +224,12 @@ index c23baf47..25085229 100644
}
diff --git a/ext/session/tests/rfc1867_incomplete_class_reserved_props.phpt b/ext/session/tests/rfc1867_incomplete_class_reserved_props.phpt
new file mode 100644
-index 00000000..ddad0c00
+index 00000000..b40530ea
--- /dev/null
+++ b/ext/session/tests/rfc1867_incomplete_class_reserved_props.phpt
-@@ -0,0 +1,142 @@
+@@ -0,0 +1,194 @@
+--TEST--
-+session rfc1867: the upload progress update rejects session data whose objects carry the incomplete class bookkeeping property names
++session rfc1867: the upload progress update leaves session data it cannot decode without user code untouched
+--SKIPIF--
+<?php
+include('skipif.inc');
@@ -239,19 +248,46 @@ index 00000000..ddad0c00
+file_put_contents($worker, '<?php');
+
+/* The handler decodes the record with every object kept as
-+ * __PHP_Incomplete_Class, which stores the class name of each object and the
-+ * payload of C: entries under these two property names. Data that already
-+ * carries one of them cannot be told apart from that bookkeeping, so the decode
-+ * has to fail rather than let the two meanings be confused. */
++ * __PHP_Incomplete_Class, which stores the class name of each object under
++ * __PHP_Incomplete_Class_Name. Data that already carries that property cannot
++ * be told apart from it. A Serializable payload (C:) can only be parsed by its
++ * class, and the values it holds take part in the back-reference numbering
++ * (b|r:6 below points past the three values of the payload). Such records,
++ * like corrupt ones, must reach the request unchanged: the progress is not
++ * recorded and the session is not destroyed. */
++/* name => serialized value; $ref is the number of the first top-level value,
++ * which php_serialize spends on the enclosing array */
+$cases = [
-+ 'control' => 'x|O:8:"stdClass":1:{s:1:"a";i:1;}',
-+ 'Class_Name' => 'x|O:8:"stdClass":1:{s:27:"__PHP_Incomplete_Class_Name";s:3:"foo";}',
-+ 'Class_Serialized' => 'x|O:8:"stdClass":1:{s:33:"__PHP_Incomplete_Class_Serialized";s:3:"foo";}',
-+ 'nested' => 'x|a:1:{i:0;O:8:"stdClass":1:{s:27:"__PHP_Incomplete_Class_Name";s:3:"foo";}}',
-+ 'mangled' => 'x|O:8:"stdClass":1:{s:30:"' . "\0" . 'A' . "\0" . '__PHP_Incomplete_Class_Name";s:3:"foo";}',
-+ 'corrupt' => 'x|not-serialized-at-all',
++ 'control' => function ($ref) { return ['x' => 'O:8:"stdClass":1:{s:1:"a";i:1;}']; },
++ 'Class_Name' => function ($ref) { return ['x' => 'O:8:"stdClass":1:{s:27:"__PHP_Incomplete_Class_Name";s:3:"foo";}']; },
++ 'nested' => function ($ref) { return ['x' => 'a:1:{i:0;O:8:"stdClass":1:{s:27:"__PHP_Incomplete_Class_Name";s:3:"foo";}}']; },
++ 'mangled' => function ($ref) { return ['x' => 'O:8:"stdClass":1:{s:30:"' . "\0" . 'A' . "\0" . '__PHP_Incomplete_Class_Name";s:3:"foo";}']; },
++ 'Serializable' => function ($ref) { return ['x' => 'C:4:"Cust":7:{payload}']; },
++ 'Serializable_ref' => function ($ref) { return [
++ 'p' => 'C:1:"P":30:{a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}',
++ 'a' => 'O:8:"stdClass":1:{s:1:"v";i:42;}',
++ 'b' => 'r:' . ($ref + 5) . ';',
++ ]; },
++ 'corrupt' => function ($ref) { return ['x' => 'not-serialized-at-all']; },
+];
+
++function encode_var($handler, $name, $value) {
++ if ($handler === 'php') {
++ return "$name|$value";
++ } else if ($handler === 'php_binary') {
++ return chr(strlen($name)) . $name . $value;
++ }
++ return 's:' . strlen($name) . ":\"$name\";$value";
++}
++
++function encode_record($handler, array $vars) {
++ $record = '';
++ foreach ($vars as $name => $value) {
++ $record .= encode_var($handler, $name, $value);
++ }
++ return $handler === 'php_serialize' ? 'a:' . count($vars) . ":{{$record}}" : $record;
++}
++
+$boundary = '---------------------------20896060251896012921717172737';
+$body = "--$boundary\r\n"
+ . "Content-Disposition: form-data; name=\"PHPSESSID\"\r\n\r\n$sid\r\n"
@@ -275,7 +311,6 @@ index 00000000..ddad0c00
+ 'session.use_only_cookies' => '0',
+ 'session.cache_limiter' => '',
+ 'session.save_handler' => 'files',
-+ 'session.serialize_handler' => 'php',
+ 'session.upload_progress.enabled' => '1',
+ 'session.upload_progress.cleanup' => '0',
+ 'session.upload_progress.prefix' => 'upload_progress_',
@@ -305,7 +340,6 @@ index 00000000..ddad0c00
+foreach ($extensions as $module) {
+ $cmd .= ' -d ' . escapeshellarg("extension=$module");
+}
-+$cmd .= ' -f ' . escapeshellarg($worker);
+
+$env = getenv();
+$env['REDIRECT_STATUS'] = '1';
@@ -316,12 +350,16 @@ index 00000000..ddad0c00
+$env['PATH_TRANSLATED'] = $worker;
+$env['QUERY_STRING'] = '';
+
-+foreach ($cases as $label => $record) {
++foreach (['php', 'php_binary', 'php_serialize'] as $handler) {
++ echo "$handler:\n";
++ foreach ($cases as $label => $vars) {
++ $vars = $vars($handler === 'php_serialize' ? 2 : 1);
++ $record = encode_record($handler, $vars);
+ file_put_contents($file, $record);
+
+ $pipes = [];
+ $proc = proc_open(
-+ $cmd,
++ $cmd . ' -d session.serialize_handler=' . $handler . ' -f ' . escapeshellarg($worker),
+ [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
+ $pipes,
+ $dir,
@@ -334,14 +372,19 @@ index 00000000..ddad0c00
+ fclose($pipes[2]);
+ proc_close($proc);
+
-+ /* A refused decode must leave exactly one warning: the handler stops there
-+ * instead of writing the progress into the empty session it was left with,
-+ * which would add a second warning about the save path. */
-+ $kept = file_exists($file) && strncmp(file_get_contents($file), $record, strlen($record)) === 0;
-+ printf("%-16s warnings: %d, decode refused: %-5s record kept: %s\n", $label,
++ /* without the progress the file must be byte for byte the same, with it
++ * every variable must still be there */
++ $after = file_exists($file) ? file_get_contents($file) : '';
++ $progress = strpos($after, 'upload_progress_key') !== false;
++ $kept = $progress || $after === $record;
++ foreach ($vars as $name => $value) {
++ $kept = $kept && strpos($after, encode_var($handler, $name, $value)) !== false;
++ }
++ printf("%-16s warnings: %d, progress: %-5s record kept: %s\n", $label,
+ substr_count($out, 'Warning:'),
-+ var_export(strpos($out, 'Session has been destroyed') !== false, true),
++ var_export($progress, true),
+ var_export($kept, true));
++ }
+}
+
+?>
@@ -355,18 +398,36 @@ index 00000000..ddad0c00
+ at rmdir($dir);
+?>
+--EXPECT--
-+control warnings: 0, decode refused: false record kept: true
-+Class_Name warnings: 1, decode refused: true record kept: false
-+Class_Serialized warnings: 1, decode refused: true record kept: false
-+nested warnings: 1, decode refused: true record kept: false
-+mangled warnings: 0, decode refused: false record kept: true
-+corrupt warnings: 1, decode refused: true record kept: false
++php:
++control warnings: 0, progress: true record kept: true
++Class_Name warnings: 0, progress: false record kept: true
++nested warnings: 0, progress: false record kept: true
++mangled warnings: 0, progress: true record kept: true
++Serializable warnings: 0, progress: false record kept: true
++Serializable_ref warnings: 0, progress: false record kept: true
++corrupt warnings: 0, progress: false record kept: true
++php_binary:
++control warnings: 0, progress: true record kept: true
++Class_Name warnings: 0, progress: false record kept: true
++nested warnings: 0, progress: false record kept: true
++mangled warnings: 0, progress: true record kept: true
++Serializable warnings: 0, progress: false record kept: true
++Serializable_ref warnings: 0, progress: false record kept: true
++corrupt warnings: 0, progress: false record kept: true
++php_serialize:
++control warnings: 0, progress: true record kept: true
++Class_Name warnings: 0, progress: false record kept: true
++nested warnings: 0, progress: false record kept: true
++mangled warnings: 0, progress: true record kept: true
++Serializable warnings: 0, progress: false record kept: true
++Serializable_ref warnings: 0, progress: false record kept: true
++corrupt warnings: 0, progress: false record kept: true
diff --git a/ext/session/tests/rfc1867_no_user_code.phpt b/ext/session/tests/rfc1867_no_user_code.phpt
new file mode 100644
-index 00000000..8399ab9f
+index 00000000..d03aecc3
--- /dev/null
+++ b/ext/session/tests/rfc1867_no_user_code.phpt
-@@ -0,0 +1,199 @@
+@@ -0,0 +1,187 @@
+--TEST--
+session rfc1867: the upload progress update resolves no classes, keeps the session data intact and leaves no $_SESSION behind
+--SKIPIF--
@@ -386,19 +447,17 @@ index 00000000..8399ab9f
+$worker = "$dir/worker.php";
+
+/* A hand-written record, as session_encode() produces it for the `php` handler:
-+ * an object with __wakeup(), a Serializable payload (C:), an object shared
-+ * through a back-reference (r:), and a class that does not exist. Writing it directly leaves the session module untouched until
-+ * the upload progress handler runs, as in a real request. */
++ * objects with __wakeup(), one of them shared through a back-reference (r:),
++ * and a class that does not exist. Writing it directly leaves the session
++ * module untouched until the upload progress handler runs, as in a real request. */
+$record = 'w|O:1:"W":1:{s:1:"a";i:1;}'
-+ . 'c|C:4:"Cust":7:{payload}'
-+ . 'r|a:2:{i:0;C:4:"Cust":7:{payload}i:1;r:5;}'
++ . 'r|a:2:{i:0;O:1:"W":1:{s:1:"a";i:2;}i:1;r:4;}'
+ . 'm|O:7:"Missing":1:{s:1:"x";i:3;}';
+file_put_contents($file, $record);
+
+/* None of these classes exist while the handler decodes the record: the request
-+ * script is not even compiled yet. Without the raw payload, C:4:"Cust" would
-+ * lose it. The handler keeps every object as __PHP_Incomplete_Class instead
-+ * and writes it back unchanged. */
++ * script is not even compiled yet. The handler keeps every object as
++ * __PHP_Incomplete_Class instead and writes it back unchanged. */
+file_put_contents($worker, <<<'PHP'
+<?php
+$record = getenv('TEST_SESSION_RECORD');
@@ -416,16 +475,6 @@ index 00000000..8399ab9f
+ }
+}
+
-+class Cust implements Serializable {
-+ public $x = 'payload';
-+ function serialize() {
-+ return $this->x;
-+ }
-+ function unserialize($d) {
-+ $this->x = $d;
-+ }
-+}
-+
+/* The handler needs a $_SESSION to decode the record into, and registers it in
+ * the global symbol table. This script has not called session_start(), so it
+ * must not be left behind: it would otherwise expose the session data of
@@ -441,8 +490,8 @@ index 00000000..8399ab9f
+echo "--- session_start():\n";
+session_start();
+var_dump(session_id());
-+var_dump($_SESSION['w']->a, $_SESSION['c']->x);
-+var_dump($_SESSION['r'][0]->x, $_SESSION['r'][0] === $_SESSION['r'][1]);
++var_dump($_SESSION['w']->a, $_SESSION['r'][0]->a);
++var_dump($_SESSION['r'][0] === $_SESSION['r'][1]);
+var_dump($_SESSION['m']);
+var_dump(isset($_SESSION['upload_progress_key']['bytes_processed']));
+session_destroy();
@@ -554,10 +603,10 @@ index 00000000..8399ab9f
+--- session_start():
+autoload(Missing)
+W::__wakeup
++W::__wakeup
+string(17) "rfc1867nousercode"
+int(1)
-+string(7) "payload"
-+string(7) "payload"
++int(2)
+bool(true)
+object(__PHP_Incomplete_Class)#%d (2) {
+ ["__PHP_Incomplete_Class_Name"]=>
@@ -645,31 +694,11 @@ index 881b1d5b..77211b65 100644
- }
-}
+NULL
-diff --git a/ext/standard/php_incomplete_class.h b/ext/standard/php_incomplete_class.h
-index 52a43678..a49b0740 100644
---- a/ext/standard/php_incomplete_class.h
-+++ b/ext/standard/php_incomplete_class.h
-@@ -45,6 +45,9 @@
-
- #define INCOMPLETE_CLASS "__PHP_Incomplete_Class"
- #define MAGIC_MEMBER "__PHP_Incomplete_Class_Name"
-+/* Set by php_var_unserialize() in incomplete_classes_only mode: the raw payload
-+ * of a C: value. The serializer writes it back unchanged. */
-+#define MAGIC_MEMBER_SERIALIZED "__PHP_Incomplete_Class_Serialized"
-
- #ifdef __cplusplus
- extern "C" {
diff --git a/ext/standard/php_var.h b/ext/standard/php_var.h
-index ac3bae8d..3d78a8c9 100644
+index ac3bae8d..da0c42b4 100644
--- a/ext/standard/php_var.h
+++ b/ext/standard/php_var.h
-@@ -45,11 +45,13 @@ PHPAPI int php_var_unserialize_ref(zval *rval, const unsigned char **p, const un
- PHPAPI int php_var_unserialize_intern(zval *rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash);
-
- PHPAPI php_serialize_data_t php_var_serialize_init(void);
-+PHPAPI void php_var_serialize_set_incomplete_classes_only(php_serialize_data_t d, zend_bool incomplete_classes_only);
- PHPAPI void php_var_serialize_destroy(php_serialize_data_t d);
- PHPAPI php_unserialize_data_t php_var_unserialize_init(void);
+@@ -50,6 +50,7 @@ PHPAPI php_unserialize_data_t php_var_unserialize_init(void);
PHPAPI void php_var_unserialize_destroy(php_unserialize_data_t d);
PHPAPI HashTable *php_var_unserialize_get_allowed_classes(php_unserialize_data_t d);
PHPAPI void php_var_unserialize_set_allowed_classes(php_unserialize_data_t d, HashTable *classes);
@@ -677,92 +706,8 @@ index ac3bae8d..3d78a8c9 100644
#define PHP_VAR_SERIALIZE_INIT(d) \
(d) = php_var_serialize_init()
-diff --git a/ext/standard/var.c b/ext/standard/var.c
-index 10673d85..7303eebe 100644
---- a/ext/standard/var.c
-+++ b/ext/standard/var.c
-@@ -34,6 +34,9 @@
- struct php_serialize_data {
- HashTable ht;
- uint32_t n;
-+ /* Write back the C: payloads kept by php_var_unserialize() in
-+ * incomplete_classes_only mode, see php_var_serialize_incomplete_raw() */
-+ zend_bool incomplete_classes_only;
- };
-
- #define COMMON (is_ref ? "&" : "")
-@@ -832,6 +835,39 @@ undef_prop:
- }
- /* }}} */
-
-+static zend_bool php_var_serialize_incomplete_raw(smart_str *buf, zval *struc)
-+{
-+ HashTable *props = Z_OBJ_P(struc)->properties;
-+ zend_string *class_name;
-+ zval *member;
-+
-+ if (!props) {
-+ return 0;
-+ }
-+
-+ member = zend_hash_str_find(props, MAGIC_MEMBER_SERIALIZED, sizeof(MAGIC_MEMBER_SERIALIZED) - 1);
-+ if (member && Z_TYPE_P(member) == IS_STRING) {
-+ class_name = php_lookup_class_name(struc);
-+ if (!class_name) {
-+ return 0;
-+ }
-+ smart_str_appendl(buf, "C:", 2);
-+ smart_str_append_unsigned(buf, ZSTR_LEN(class_name));
-+ smart_str_appendl(buf, ":\"", 2);
-+ smart_str_append(buf, class_name);
-+ smart_str_appendl(buf, "\":", 2);
-+ smart_str_append_unsigned(buf, Z_STRLEN_P(member));
-+ smart_str_appendl(buf, ":{", 2);
-+ smart_str_append(buf, Z_STR_P(member));
-+ smart_str_appendc(buf, '}');
-+ zend_string_release_ex(class_name, 0);
-+ return 1;
-+ }
-+
-+ /* Other incomplete classes are handled using the normal path */
-+ return 0;
-+}
-+
- static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_data_t var_hash) /* {{{ */
- {
- zend_long var_already;
-@@ -893,6 +929,10 @@ again:
- case IS_OBJECT: {
- zend_class_entry *ce = Z_OBJCE_P(struc);
-
-+ if (ce == PHP_IC_ENTRY && var_hash && var_hash->incomplete_classes_only && php_var_serialize_incomplete_raw(buf, struc)) {
-+ return;
-+ }
-+
- if (ce->serialize != NULL) {
- /* has custom handler */
- unsigned char *serialized_data = NULL;
-@@ -1032,6 +1072,7 @@ PHPAPI php_serialize_data_t php_var_serialize_init() {
- d = emalloc(sizeof(struct php_serialize_data));
- zend_hash_init(&d->ht, 16, NULL, ZVAL_PTR_DTOR, 0);
- d->n = 0;
-+ d->incomplete_classes_only = 0;
- if (!BG(serialize_lock)) {
- BG(serialize).data = d;
- BG(serialize).level = 1;
-@@ -1043,6 +1084,10 @@ PHPAPI php_serialize_data_t php_var_serialize_init() {
- return d;
- }
-
-+PHPAPI void php_var_serialize_set_incomplete_classes_only(php_serialize_data_t d, zend_bool incomplete_classes_only) {
-+ d->incomplete_classes_only = incomplete_classes_only;
-+}
-+
- PHPAPI void php_var_serialize_destroy(php_serialize_data_t d) {
- /* fprintf(stderr, "SERIALIZE_DESTROY == lock: %u, level: %u\n", BG(serialize_lock), BG(serialize).level); */
- if (BG(serialize_lock) || BG(serialize).level == 1) {
diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re
-index 1eff008d..37dd4a5e 100644
+index 1eff008d..7fb83752 100644
--- a/ext/standard/var_unserializer.re
+++ b/ext/standard/var_unserializer.re
@@ -27,6 +27,10 @@ struct php_unserialize_data {
@@ -771,7 +716,7 @@ index 1eff008d..37dd4a5e 100644
HashTable *allowed_classes;
+ /* Represent every object as __PHP_Incomplete_Class, without resolving its
+ * class: no autoloading, no unserialize_callback_func, no __wakeup().
-+ * O: and C: values both serialize back to the same bytes. */
++ * O: values serialize back to the same bytes, C: values are refused. */
+ zend_bool incomplete_classes_only;
};
@@ -786,30 +731,15 @@ index 1eff008d..37dd4a5e 100644
/* {{{ reference-handling for unserializer: var_* */
-@@ -393,6 +400,16 @@ static inline size_t parse_uiv(const unsigned char *p)
-
- static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER, int as_key);
-
-+/* The members that incomplete_classes_only mode writes itself: the class name of
-+ * every object, and the payload kept for C: entries. Data that already carries
-+ * one of them cannot be told apart from that bookkeeping, so it is rejected
-+ * rather than silently overwritten. */
-+static zend_always_inline zend_bool is_incomplete_class_reserved_member(const zend_string *name)
-+{
-+ return zend_string_equals_literal(name, MAGIC_MEMBER)
-+ || zend_string_equals_literal(name, MAGIC_MEMBER_SERIALIZED);
-+}
-+
- static zend_always_inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, zend_long elements, int objprops)
- {
- while (elements-- > 0) {
-@@ -436,6 +453,13 @@ numeric_key:
+@@ -436,6 +443,15 @@ numeric_key:
return 0;
}
} else {
++ /* incomplete_classes_only mode stores the class name of every object
++ * under this name; data that carries it already cannot be told apart */
+ if (UNEXPECTED((*var_hash)->incomplete_classes_only)
+ && Z_TYPE(key) == IS_STRING
-+ && UNEXPECTED(is_incomplete_class_reserved_member(Z_STR(key)))) {
++ && UNEXPECTED(zend_string_equals_literal(Z_STR(key), MAGIC_MEMBER))) {
+ zval_ptr_dtor(&key);
+ return 0;
+ }
@@ -817,34 +747,7 @@ index 1eff008d..37dd4a5e 100644
if (EXPECTED(Z_TYPE(key) == IS_STRING)) {
string_key:
if (Z_TYPE_P(rval) == IS_OBJECT
-@@ -532,7 +556,7 @@ static inline int finish_nested_data(UNSERIALIZE_PARAMETER)
- return 1;
- }
-
--static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce)
-+static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce, zend_bool keep_payload)
- {
- zend_long datalen;
-
-@@ -552,7 +576,16 @@ static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce)
- return 0;
- }
-
-- if (ce->unserialize == NULL) {
-+ if (keep_payload) {
-+ /* The class was not resolved (see php_var_unserialize_set_incomplete_classes_only()):
-+ * keep the payload verbatim, so that the object serializes back to the same bytes. */
-+ zval payload;
-+
-+ ZEND_ASSERT(ce == PHP_IC_ENTRY);
-+ ZVAL_STRINGL(&payload, (const char *) *p, datalen);
-+ object_init_ex(rval, ce);
-+ zend_hash_str_update(Z_OBJPROP_P(rval), MAGIC_MEMBER_SERIALIZED, sizeof(MAGIC_MEMBER_SERIALIZED) - 1, &payload);
-+ } else if (ce->unserialize == NULL) {
- zend_error(E_WARNING, "Class %s has no unserializer", ZSTR_VAL(ce->name));
- object_init_ex(rval, ce);
- } else if (ce->unserialize(rval, ce, (const unsigned char*)*p, datalen, (zend_unserialize_data *)var_hash) != SUCCESS) {
-@@ -964,6 +997,13 @@ object ":" uiv ":" ["] {
+@@ -964,6 +980,13 @@ object ":" uiv ":" ["] {
class_name = zend_string_init(str, len, 0);
do {
@@ -858,12 +761,18 @@ index 1eff008d..37dd4a5e 100644
if(!unserialize_allowed_class(class_name, var_hash)) {
incomplete_class = 1;
ce = PHP_IC_ENTRY;
-@@ -1043,7 +1083,7 @@ object ":" uiv ":" ["] {
+@@ -1043,6 +1066,14 @@ object ":" uiv ":" ["] {
if (custom_object) {
int ret;
-- ret = object_custom(UNSERIALIZE_PASSTHRU, ce);
-+ ret = object_custom(UNSERIALIZE_PASSTHRU, ce, (*var_hash)->incomplete_classes_only);
++ if ((*var_hash)->incomplete_classes_only) {
++ /* Values that Serializable::unserialize() would decode from the payload
++ * share the reference numbering of the enclosing data: without the
++ * class, the back-references after it cannot be resolved */
++ zend_string_release_ex(class_name, 0);
++ return 0;
++ }
++
+ ret = object_custom(UNSERIALIZE_PASSTHRU, ce);
if (ret && incomplete_class) {
- php_store_class_name(rval, ZSTR_VAL(class_name), len2);
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/php.git/commitdiff/6c782c7c03b1e221052436887e5e8360e3aae673
More information about the pld-cvs-commit
mailing list