Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4708,7 +4708,7 @@ static struct jit_observer_fcall_is_unobserved_data jit_observer_fcall_is_unobse
ir_ref observer_handler_user = ir_ADD_OFFSET(run_time_cache, zend_observer_fcall_op_array_extension * sizeof(void *));

ir_MERGE_WITH(if_internal_func_end);
*observer_handler = ir_PHI_2(IR_ADDR, observer_handler_internal, observer_handler_user);
*observer_handler = ir_PHI_2(IR_ADDR, observer_handler_user, observer_handler_internal);
}

// JIT: if (*observer_handler == ZEND_OBSERVER_NONE_OBSERVED) {
Expand Down
33 changes: 33 additions & 0 deletions ext/opcache/tests/jit/gh22158.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
GH-22158 (Tracing JIT dispatches observer begin handler through the wrong run_time_cache slot on megamorphic calls)
--EXTENSIONS--
opcache
zend_test
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.jit=tracing
opcache.jit_buffer_size=32M
opcache.jit_max_polymorphic_calls=0
zend_test.observer.enabled=1
zend_test.observer.observe_all=1
zend_test.observer.show_output=0
zend_test.observer.reserve_op_array_handle=1
--FILE--
<?php
interface S { public function f(): int; }
final class A implements S { public function f(): int { return 1; } }
final class B implements S { public function f(): int { return 2; } }
final class C implements S { public function f(): int { return 3; } }
final class D implements S { public function f(): int { return 4; } }
final class E implements S { public function f(): int { return 5; } }

$o = [new A, new B, new C, new D, new E];
$t = 0;
for ($i = 0; $i < 200000; $i++) {
$t += $o[$i % 5]->f();
}
echo $t, "\n";
?>
--EXPECT--
600000
4 changes: 2 additions & 2 deletions ext/pdo_sqlite/pdo_sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static int php_pdosqlite3_stream_seek(php_stream *stream, zend_off_t offset, int
switch(whence) {
case SEEK_CUR:
if (offset < 0) {
if (sqlite3_stream->position < (size_t)(-offset)) {
if (sqlite3_stream->position < -(size_t)offset) {
sqlite3_stream->position = 0;
*newoffs = -1;
return -1;
Expand Down Expand Up @@ -241,7 +241,7 @@ static int php_pdosqlite3_stream_seek(php_stream *stream, zend_off_t offset, int
sqlite3_stream->position = sqlite3_stream->size;
*newoffs = -1;
return -1;
} else if (sqlite3_stream->size < (size_t)(-offset)) {
} else if (sqlite3_stream->size < -(size_t)offset) {
sqlite3_stream->position = 0;
*newoffs = -1;
return -1;
Expand Down
23 changes: 23 additions & 0 deletions ext/pdo_sqlite/tests/gh20964.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-20964 (fseek() on PDO SQLite blob stream with PHP_INT_MIN causes undefined behavior)
--EXTENSIONS--
pdo_sqlite
--FILE--
<?php
$db = new Pdo\Sqlite('sqlite::memory:');

$db->exec('CREATE TABLE test (id INTEGER PRIMARY KEY, data BLOB)');
$db->exec("INSERT INTO test (id, data) VALUES (1, 'hello')");

$stream = $db->openBlob('test', 'data', 1);

var_dump(fseek($stream, PHP_INT_MIN, SEEK_END));

rewind($stream);
var_dump(fseek($stream, PHP_INT_MIN, SEEK_CUR));

fclose($stream);
?>
--EXPECT--
int(-1)
int(-1)
10 changes: 5 additions & 5 deletions ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,12 +1158,12 @@ int make_http_soap_request(
zend_string_release_ex(http_headers, 0);
zend_string_release_ex(http_body, 0);
if (new_uri->scheme == NULL && new_uri->path != NULL) {
new_uri->scheme = new_uri->scheme ? zend_string_copy(new_uri->scheme) : NULL;
new_uri->host = new_uri->host ? zend_string_copy(new_uri->host) : NULL;
new_uri->port = new_uri->port;
new_uri->scheme = uri->scheme ? zend_string_copy(uri->scheme) : NULL;
new_uri->host = uri->host ? zend_string_copy(uri->host) : NULL;
new_uri->port = uri->port;
if (new_uri->path && ZSTR_VAL(new_uri->path)[0] != '/') {
if (new_uri->path) {
char *t = ZSTR_VAL(new_uri->path);
if (uri->path) {
char *t = ZSTR_VAL(uri->path);
char *p = strrchr(t, '/');
if (p) {
zend_string *s = zend_string_concat2(t, (p - t) + 1, ZSTR_VAL(new_uri->path), ZSTR_LEN(new_uri->path));
Expand Down
49 changes: 49 additions & 0 deletions ext/soap/tests/bugs/relative_redirect.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
SOAP client follows a redirect with a scheme-less (relative) Location
--EXTENSIONS--
soap
--SKIPIF--
<?php
if (!file_exists(__DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc")) {
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
}
?>
--FILE--
<?php
include __DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc";

$args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX];
if (php_ini_loaded_file()) {
$args[] = "-c";
$args[] = php_ini_loaded_file();
}

$code = <<<'PHP'
if ($_SERVER["REQUEST_URI"] === "/redirected") {
header("Content-Type: text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>',
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">',
'<SOAP-ENV:Body><fooResponse><result>ok</result></fooResponse></SOAP-ENV:Body>',
'</SOAP-ENV:Envelope>';
} else {
http_response_code(302);
header("Location: /redirected");
}
PHP;

php_cli_server_start($code, null, $args);

$client = new SoapClient(null, [
'location' => 'http://' . PHP_CLI_SERVER_ADDRESS . '/start',
'uri' => 'test-uri',
]);

try {
$client->__soapCall("foo", []);
echo "redirect followed\n";
} catch (SoapFault $e) {
echo "SoapFault: " . $e->getMessage() . "\n";
}
?>
--EXPECT--
redirect followed
49 changes: 49 additions & 0 deletions ext/soap/tests/bugs/relative_redirect_path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
SOAP client follows a redirect with a relative Location resolved against the request path
--EXTENSIONS--
soap
--SKIPIF--
<?php
if (!file_exists(__DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc")) {
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
}
?>
--FILE--
<?php
include __DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc";

$args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX];
if (php_ini_loaded_file()) {
$args[] = "-c";
$args[] = php_ini_loaded_file();
}

$code = <<<'PHP'
if ($_SERVER["REQUEST_URI"] === "/svc/redirected") {
header("Content-Type: text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>',
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">',
'<SOAP-ENV:Body><fooResponse><result>ok</result></fooResponse></SOAP-ENV:Body>',
'</SOAP-ENV:Envelope>';
} else {
http_response_code(302);
header("Location: redirected");
}
PHP;

php_cli_server_start($code, null, $args);

$client = new SoapClient(null, [
'location' => 'http://' . PHP_CLI_SERVER_ADDRESS . '/svc/start',
'uri' => 'test-uri',
]);

try {
$client->__soapCall("foo", []);
echo "redirect followed\n";
} catch (SoapFault $e) {
echo "SoapFault: " . $e->getMessage() . "\n";
}
?>
--EXPECT--
redirect followed
4 changes: 2 additions & 2 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ static int php_sqlite3_stream_seek(php_stream *stream, zend_off_t offset, int wh
switch(whence) {
case SEEK_CUR:
if (offset < 0) {
if (sqlite3_stream->position < (size_t)(-offset)) {
if (sqlite3_stream->position < -(size_t)offset) {
sqlite3_stream->position = 0;
*newoffs = -1;
return -1;
Expand Down Expand Up @@ -1199,7 +1199,7 @@ static int php_sqlite3_stream_seek(php_stream *stream, zend_off_t offset, int wh
sqlite3_stream->position = sqlite3_stream->size;
*newoffs = -1;
return -1;
} else if (sqlite3_stream->size < (size_t)(-offset)) {
} else if (sqlite3_stream->size < -(size_t)offset) {
sqlite3_stream->position = 0;
*newoffs = -1;
return -1;
Expand Down
24 changes: 24 additions & 0 deletions ext/sqlite3/tests/gh20964.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-20964 (fseek() on SQLite3 blob stream with PHP_INT_MIN causes undefined behavior)
--EXTENSIONS--
sqlite3
--FILE--
<?php
require_once __DIR__ . '/new_db.inc';

$db->exec('CREATE TABLE test (id INTEGER PRIMARY KEY, data BLOB)');
$db->exec("INSERT INTO test (id, data) VALUES (1, 'hello')");

$stream = $db->openBlob('test', 'data', 1);

var_dump(fseek($stream, PHP_INT_MIN, SEEK_END));

rewind($stream);
var_dump(fseek($stream, PHP_INT_MIN, SEEK_CUR));

fclose($stream);
$db->close();
?>
--EXPECT--
int(-1)
int(-1)
5 changes: 5 additions & 0 deletions ext/zend_test/observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "php_test.h"
#include "observer.h"
#include "zend_observer.h"
#include "zend_extensions.h"
#include "zend_smart_str.h"
#include "ext/standard/php_var.h"
#include "zend_generators.h"
Expand Down Expand Up @@ -398,6 +399,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("zend_test.observer.fiber_switch", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_fiber_switch, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.observer.fiber_destroy", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_fiber_destroy, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.observer.execute_internal", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_execute_internal, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.observer.reserve_op_array_handle", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_reserve_op_array_handle, zend_zend_test_globals, zend_test_globals)
PHP_INI_END()

void zend_test_observer_init(INIT_FUNC_ARGS)
Expand All @@ -406,6 +408,9 @@ void zend_test_observer_init(INIT_FUNC_ARGS)
if (type != MODULE_TEMPORARY) {
REGISTER_INI_ENTRIES();
if (ZT_G(observer_enabled)) {
if (ZT_G(observer_reserve_op_array_handle)) {
zend_get_op_array_extension_handle("zend_test");
}
zend_observer_fcall_register(observer_fcall_init);
}
} else {
Expand Down
1 change: 1 addition & 0 deletions ext/zend_test/php_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ZEND_BEGIN_MODULE_GLOBALS(zend_test)
int observer_fiber_switch;
int observer_fiber_destroy;
int observer_execute_internal;
int observer_reserve_op_array_handle;
HashTable *global_weakmap;
int replace_zend_execute_ex;
int register_passes;
Expand Down
4 changes: 2 additions & 2 deletions main/streams/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe
switch(whence) {
case SEEK_CUR:
if (offset < 0) {
if (ms->fpos < (size_t)(-offset)) {
if (ms->fpos < -(size_t)offset) {
ms->fpos = 0;
*newoffs = -1;
return -1;
Expand Down Expand Up @@ -163,7 +163,7 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe
stream->eof = 0;
stream->fatal_error = 0;
return 0;
} else if (ZSTR_LEN(ms->data) < (size_t)(-offset)) {
} else if (ZSTR_LEN(ms->data) < -(size_t)offset) {
ms->fpos = 0;
*newoffs = -1;
return -1;
Expand Down
22 changes: 22 additions & 0 deletions tests/basic/gh20964.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-20964 (fseek() on php://memory with PHP_INT_MIN causes undefined behavior)
--FILE--
<?php
$stream = fopen('php://memory', 'r+');
fwrite($stream, 'hello');
rewind($stream);

var_dump(fseek($stream, PHP_INT_MIN, SEEK_END));
var_dump(ftell($stream));

rewind($stream);
var_dump(fseek($stream, PHP_INT_MIN, SEEK_CUR));
var_dump(ftell($stream));

fclose($stream);
?>
--EXPECT--
int(-1)
bool(false)
int(-1)
bool(false)