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
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ PHP 8.6 UPGRADE NOTES

- Standard:
. Improved performance of array_fill_keys().
. Improved performance of array_walk().
6 changes: 1 addition & 5 deletions ext/fileinfo/libmagic/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
#include "php_libmagic.h"

#ifndef HAVE_STDINT_H
#define HAVE_STDINT_H 1
#endif

#ifndef HAVE_STDINT_H
#define HAVE_STDINT_H 1
# define HAVE_STDINT_H 1
#endif

#ifndef HAVE_VISIBILITY
Expand Down
1 change: 1 addition & 0 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
ZVAL_COPY_VALUE(&dataset, return_value);
zend_result obj_initialized = object_init_ex(return_value, ce);
if (UNEXPECTED(obj_initialized == FAILURE)) {
zval_ptr_dtor(&dataset);
RETURN_THROWS();
}
if (!ce->default_properties_count && !ce->__set) {
Expand Down
18 changes: 4 additions & 14 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ static zend_result php_array_walk(
/* Set up known arguments */
ZVAL_UNDEF(&args[1]);
if (userdata) {
ZVAL_COPY(&args[2], userdata);
ZVAL_COPY_VALUE(&args[2], userdata);
}

fci.retval = &retval;
Expand Down Expand Up @@ -1531,21 +1531,14 @@ static zend_result php_array_walk(
}
zval_ptr_dtor(&ref);
} else {
ZVAL_COPY(&args[0], zv);
ZVAL_COPY_VALUE(&args[0], zv);

/* Call the userland function */
result = zend_call_function(&fci, &context->fci_cache);
if (result == SUCCESS) {
zval_ptr_dtor(&retval);
}

zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&retval);
}

if (Z_TYPE(args[1]) != IS_UNDEF) {
zval_ptr_dtor(&args[1]);
ZVAL_UNDEF(&args[1]);
}
zval_ptr_dtor_str(&args[1]);

if (result == FAILURE) {
break;
Expand All @@ -1565,9 +1558,6 @@ static zend_result php_array_walk(
}
} while (!EG(exception));

if (userdata) {
zval_ptr_dtor(&args[2]);
}
zend_hash_iterator_del(ht_iter);
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/tidy/tests/018.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tidy
$x = tidy_repair_string("<p>abra\0cadabra</p>",
array( 'show-body-only' => true,
'clean' => false,
'newline' => "\n")
'newline' => "LF")
);
var_dump($x);
?>
Expand Down
175 changes: 175 additions & 0 deletions ext/tidy/tests/gh20374.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
--TEST--
GH-20374 (PHP with tidy and custom-tags)
--EXTENSIONS--
tidy
--CREDITS--
franck-paul
--FILE--
<?php

class MyStringable {
public function __construct(private $ret) {}

public function __toString(): string {
return $this->ret;
}
}

class MyThrowingStringable {
public function __toString(): string {
throw new Error('no');
}
}

$values = [
'string blocklevel' => 'blocklevel',
'int' => 1,
'double overflow' => (string) (2.0**80.0),
'numeric string int 1' => '1',
'numeric string double 1.0' => '1.0',
'false' => false,
'true' => true,
'NAN' => NAN,
'INF' => INF,
'object with numeric string int 0' => new MyStringable('0'),
'object with string blocklevel' => new MyStringable('blocklevel'),
'object with string empty' => new MyStringable('empty'),
'object with exception' => new MyThrowingStringable,
];

foreach ($values as $key => $value) {
echo "--- $key ---\n";
$str = '<custom-html-element>test</custom-html-element>';

$config = [
'custom-tags' => $value,
];

$tidy = new tidy();
try {
$tidy->parseString($str, $config, 'utf8');
echo $tidy->value, "\n";
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}
}

?>
--EXPECTF--
--- string blocklevel ---
<html>
<head>
<title></title>
</head>
<body>
<custom-html-element>test</custom-html-element>
</body>
</html>
--- int ---
<html>
<head>
<title></title>
</head>
<body>
<custom-html-element>test</custom-html-element>
</body>
</html>
--- double overflow ---

Warning: The float-string "1.2089258196146E+24" is not representable as an int, cast occurred in %s on line %d
<html>
<head>
<title></title>
</head>
<body>
test
</body>
</html>
--- numeric string int 1 ---
<html>
<head>
<title></title>
</head>
<body>
<custom-html-element>test</custom-html-element>
</body>
</html>
--- numeric string double 1.0 ---
<html>
<head>
<title></title>
</head>
<body>
<custom-html-element>test</custom-html-element>
</body>
</html>
--- false ---
<html>
<head>
<title></title>
</head>
<body>
test
</body>
</html>
--- true ---
<html>
<head>
<title></title>
</head>
<body>
<custom-html-element>test</custom-html-element>
</body>
</html>
--- NAN ---

Warning: The float NAN is not representable as an int, cast occurred in %s on line %d
<html>
<head>
<title></title>
</head>
<body>
test
</body>
</html>
--- INF ---

Warning: The float INF is not representable as an int, cast occurred in %s on line %d
<html>
<head>
<title></title>
</head>
<body>
test
</body>
</html>
--- object with numeric string int 0 ---
<html>
<head>
<title></title>
</head>
<body>
test
</body>
</html>
--- object with string blocklevel ---
<html>
<head>
<title></title>
</head>
<body>
<custom-html-element>test</custom-html-element>
</body>
</html>
--- object with string empty ---
<custom-html-element>
<html>
<head>
<title></title>
</head>
<body>
test
</body>
</html>
--- object with exception ---
Error: no
34 changes: 30 additions & 4 deletions ext/tidy/tidy.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ static bool php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value,
{
TidyOption opt = tidyGetOptionByName(doc, optname);
zend_long lval;
zend_string *tmp_str;

if (!opt) {
zend_argument_value_error(arg, "Unknown Tidy configuration option \"%s\"", optname);
Expand All @@ -736,17 +737,42 @@ static bool php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value,

TidyOptionType type = tidyOptGetType(opt);
if (type == TidyString) {
zend_string *tmp_str;
const zend_string *str = zval_get_tmp_string(value, &tmp_str);
const bool result = tidyOptSetValue(doc, tidyOptGetId(opt), ZSTR_VAL(str));
if (UNEXPECTED(!result)) {
zend_argument_type_error(arg, "option \"%s\" does not accept \"%s\" as a value", optname, ZSTR_VAL(str));
}
zend_tmp_string_release(tmp_str);
return result;
} else if (type == TidyInteger) {
lval = zval_get_long(value);
return tidyOptSetInt(doc, tidyOptGetId(opt), lval);
} else if (type == TidyInteger) { /* integer or enum */
ZVAL_DEREF(value);
/* Enum will correspond to a non-numeric string or object */
if (Z_TYPE_P(value) == IS_STRING || Z_TYPE_P(value) == IS_OBJECT) {
double dval;
bool result;
const zend_string *str = zval_try_get_tmp_string(value, &tmp_str);
if (UNEXPECTED(!str)) {
return false;
}
uint8_t type = is_numeric_string(ZSTR_VAL(str), ZSTR_LEN(str), &lval, &dval, true);
if (type == IS_DOUBLE) {
lval = zend_dval_to_lval_cap(dval, str);
type = IS_LONG;
}
if (type == IS_LONG) {
result = tidyOptSetInt(doc, tidyOptGetId(opt), lval);
} else {
result = tidyOptSetValue(doc, tidyOptGetId(opt), ZSTR_VAL(str));
if (UNEXPECTED(!result)) {
zend_argument_type_error(arg, "option \"%s\" does not accept \"%s\" as a value", optname, ZSTR_VAL(str));
}
}
zend_tmp_string_release(tmp_str);
return result;
} else {
lval = zval_get_long(value);
return tidyOptSetInt(doc, tidyOptGetId(opt), lval);
}
} else {
ZEND_ASSERT(type == TidyBoolean);
lval = zval_get_long(value);
Expand Down