[php-src] PHP-8.6: standard: Pass `unserialize('')` through the regular path (#23827)
| From: | Tim Düsterhus via GitHub | Date: | Tue, 22 Sep 2026 17:02:01 +0000 |
| Subject: | [php-src] PHP-8.6: standard: Pass `unserialize('')` through the regular path (#23827) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141447@lists.php.net to get a copy of this message | ||
Author: Tim Düsterhus (TimWolla)
Committer: GitHub (web-flow)
Pusher: TimWolla
Date: 2026-09-22T19:01:58+02:00
Commit: https://github.com/php/php-src/commit/262865195d327c80a54c760e67ce35398f85ca79
Raw diff: https://github.com/php/php-src/commit/262865195d327c80a54c760e67ce35398f85ca79.diff
standard: Pass
unserialize('') through the regular path (#23827)
Previously unserialize() with an empty string as input was handled specially,
returning false (indicating an error), but without emitting an associated
warning. We can just pass it through the regular path, which will also return
false (including the warning) and will also avoid a check that is almost
never taken in practice.
Fixes php/php-src#23780.
Changed paths:
A ext/standard/tests/serialize/gh23780.phpt
M NEWS
M ext/opcache/tests/jit/assign_048.phpt
M ext/standard/var.c
Diff:
diff --git a/NEWS b/NEWS
index 21b34cf655f8..5bac8f9cb139 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ PHP NEWS
. Fixed bug GH-23764 (Built-in server leaks a file descriptor on every HEAD
request for a static file). (jakubskopal)
+- Standard:
+ . Fixed bug GH-23780 (unserialize('') fails silently). (timwolla)
+
24 Sep 2026, PHP 8.6.0RC1
- Core:
diff --git a/ext/opcache/tests/jit/assign_048.phpt b/ext/opcache/tests/jit/assign_048.phpt
index ed7a058d862b..bce0fdbe67f8 100644
--- a/ext/opcache/tests/jit/assign_048.phpt
+++ b/ext/opcache/tests/jit/assign_048.phpt
@@ -20,23 +20,43 @@ test();
?>
DONE
--EXPECTF--
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+
Warning: Undefined variable $a in %sassign_048.php on line 7
DONE
diff --git a/ext/standard/tests/serialize/gh23780.phpt b/ext/standard/tests/serialize/gh23780.phpt
new file mode 100644
index 000000000000..daaf3029f215
--- /dev/null
+++ b/ext/standard/tests/serialize/gh23780.phpt
@@ -0,0 +1,9 @@
+--TEST--
+GH-23780: unserialize('') fails silently
+--FILE--
+<?php
+var_dump(unserialize(''));
+?>
+--EXPECTF--
+Warning: unserialize(): Error at offset 0 of 0 bytes in %s on line %d
+bool(false)
diff --git a/ext/standard/var.c b/ext/standard/var.c
index f94c1cf09584..7b868afddd27 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -1411,10 +1411,6 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf,
co
HashTable *class_hash = NULL, *prev_class_hash;
zend_long prev_max_depth, prev_cur_depth;
- if (buf_len == 0) {
- RETURN_FALSE;
- }
-
p = (const unsigned char*) buf;
PHP_VAR_UNSERIALIZE_INIT(var_hash);