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 .github/actions/apt-x32/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ runs:
libxml2-dev:i386 \
libxpm-dev:i386 \
libxslt1-dev:i386 \
firebird-dev:i386 \
locales \
make \
pkg-config:i386 \
Expand Down
1 change: 1 addition & 0 deletions .github/actions/configure-x32/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ runs:
--with-pgsql \
--with-pdo-pgsql \
--with-pdo-sqlite \
--with-pdo-firebird \
--without-pear \
--enable-gd \
--with-jpeg \
Expand Down
4 changes: 3 additions & 1 deletion .github/actions/test-linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ runs:
export PDO_PGSQL_TEST_DSN="pgsql:host=localhost port=5432 dbname=test user=postgres password=postgres"
fi
export PDO_FIREBIRD_TEST_DATABASE=test.fdb
export PDO_FIREBIRD_TEST_DSN=firebird:dbname=localhost:test.fdb
if [[ -z "$PDO_FIREBIRD_TEST_DSN" ]]; then
export PDO_FIREBIRD_TEST_DSN=firebird:dbname=localhost:test.fdb
fi
export PDO_FIREBIRD_TEST_PASS=test
export PDO_FIREBIRD_TEST_USER=test
export ODBC_TEST_USER="odbc_test"
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ jobs:
MYSQL_TEST_HOST: mysql
PDO_MYSQL_TEST_DSN: mysql:host=mysql;dbname=test
PDO_MYSQL_TEST_HOST: mysql
PDO_FIREBIRD_TEST_DSN: firebird:dbname=firebird:test.fdb
services:
mysql:
image: mysql:8.3
Expand All @@ -155,6 +156,15 @@ jobs:
env:
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: root
firebird:
image: jacobalberty/firebird
ports:
- 3050:3050
env:
ISC_PASSWORD: test
FIREBIRD_DATABASE: test.fdb
FIREBIRD_USER: test
FIREBIRD_PASSWORD: test
steps:
- name: git checkout
uses: actions/checkout@v4
Expand Down
2 changes: 0 additions & 2 deletions ext/bcmath/bcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,8 +1801,6 @@ PHP_METHOD(BcMath_Number, round)
bc_num ret = NULL;
bc_round(intern->num, precision, rounding_mode, &ret);

bc_rm_trailing_zeros(ret);

bcmath_number_obj_t *new_intern = bcmath_number_new_obj(ret, ret->n_scale);
RETURN_OBJ(&new_intern->std);
}
Expand Down
12 changes: 12 additions & 0 deletions ext/bcmath/libbcmath/src/compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ bcmath_compare_result _bc_do_compare(bc_num n1, bc_num n2, size_t scale, bool us

/* First, compare signs. */
if (use_sign && n1->n_sign != n2->n_sign) {
/*
* scale and n->n_scale differ only in Number objects.
* This happens when explicitly specify the scale in a Number method.
*/
if ((n1->n_scale > scale || n2->n_scale > scale) &&
n1->n_len == 1 && n2->n_len == 1 &&
n1->n_value[0] == 0 && n2->n_value[0] == 0 &&
bc_is_zero_for_scale(n1, scale) && bc_is_zero_for_scale(n2, scale)
) {
/* e.g. 0.00 <=> -0.00 */
return BCMATH_EQUAL;
}
if (n1->n_sign == PLUS) {
/* Positive N1 > Negative N2 */
return BCMATH_LEFT_GREATER;
Expand Down
9 changes: 9 additions & 0 deletions ext/bcmath/libbcmath/src/str2num.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, siz
if (str_scale > scale && !auto_scale) {
fractional_end -= str_scale - scale;
str_scale = scale;

/*
* e.g. 123.0001 with scale 2 -> 123.00
* So, remove the trailing 0 again.
*/
if (str_scale > 0) {
const char *fractional_new_end = bc_skip_zero_reverse(fractional_end, fractional_ptr);
str_scale -= fractional_new_end - fractional_end;
}
}
} else {
if (full_scale) {
Expand Down
2 changes: 2 additions & 0 deletions ext/bcmath/tests/bccomp_variation002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ echo bccomp("-2.29", "2.3", "2") . "\n";
echo bccomp("2.29", "-2.3", "2") . "\n";
echo bccomp("-2.29", "-2.3", "1") . "\n";
echo bccomp("-2.29", "0", "1") . "\n";
echo bccomp("0.001", "-0.001", "1") . "\n";
?>
--EXPECT--
0
Expand All @@ -22,3 +23,4 @@ echo bccomp("-2.29", "0", "1") . "\n";
1
1
-1
0
71 changes: 71 additions & 0 deletions ext/bcmath/tests/number/methods/compare_near_zero.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
--TEST--
BcMath\Number compare() with scale
--EXTENSIONS--
bcmath
--FILE--
<?php

$values1 = [
new BcMath\Number('0.001'),
new BcMath\Number('-0.001'),
];

$values2 = [
0,
-0,
'0.0011',
'-0.0011',
];

$value1 = new BcMath\Number('0.001');

$scales = [0, 2, 3, 4];

foreach ($scales as $scale) {
echo "========== scale is {$scale} ==========\n";
foreach ($values1 as $value1) {
foreach ($values2 as $value2) {
$output = str_pad("{$value1} <=> {$value2}: ", 20, ' ', STR_PAD_LEFT);
$output .= str_pad((string) $value1->compare($value2, $scale), 2, ' ', STR_PAD_LEFT);
echo "{$output}\n";
}
}
}
?>
--EXPECT--
========== scale is 0 ==========
0.001 <=> 0: 0
0.001 <=> 0: 0
0.001 <=> 0.0011: 0
0.001 <=> -0.0011: 0
-0.001 <=> 0: 0
-0.001 <=> 0: 0
-0.001 <=> 0.0011: 0
-0.001 <=> -0.0011: 0
========== scale is 2 ==========
0.001 <=> 0: 0
0.001 <=> 0: 0
0.001 <=> 0.0011: 0
0.001 <=> -0.0011: 0
-0.001 <=> 0: 0
-0.001 <=> 0: 0
-0.001 <=> 0.0011: 0
-0.001 <=> -0.0011: 0
========== scale is 3 ==========
0.001 <=> 0: 1
0.001 <=> 0: 1
0.001 <=> 0.0011: 0
0.001 <=> -0.0011: 1
-0.001 <=> 0: -1
-0.001 <=> 0: -1
-0.001 <=> 0.0011: -1
-0.001 <=> -0.0011: 0
========== scale is 4 ==========
0.001 <=> 0: 1
0.001 <=> 0: 1
0.001 <=> 0.0011: -1
0.001 <=> -0.0011: 1
-0.001 <=> 0: -1
-0.001 <=> 0: -1
-0.001 <=> 0.0011: -1
-0.001 <=> -0.0011: 1
72 changes: 72 additions & 0 deletions ext/bcmath/tests/number/methods/round_has_trailing_zeros.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
--TEST--
BcMath\Number round() - has trailing zeros
--EXTENSIONS--
bcmath
--FILE--
<?php
foreach (RoundingMode::cases() as $mode) {
echo "========== {$mode->name} ==========\n";
foreach ([
['0.00', 1],
['0.1', 5],
['-0.300', 5],
['1.995', 2],
] as [$value, $precision]) {
$number = new BcMath\Number($value);
$output = 'value is ';
$output .= str_pad($value, 6, ' ', STR_PAD_RIGHT) . ', ';
$output .= "precision is {$precision}: ";
$output .= $number->round($precision, $mode) . "\n";
echo $output;
}
echo "\n";
}
?>
--EXPECT--
========== HalfAwayFromZero ==========
value is 0.00 , precision is 1: 0.0
value is 0.1 , precision is 5: 0.10000
value is -0.300, precision is 5: -0.30000
value is 1.995 , precision is 2: 2.00

========== HalfTowardsZero ==========
value is 0.00 , precision is 1: 0.0
value is 0.1 , precision is 5: 0.10000
value is -0.300, precision is 5: -0.30000
value is 1.995 , precision is 2: 1.99

========== HalfEven ==========
value is 0.00 , precision is 1: 0.0
value is 0.1 , precision is 5: 0.10000
value is -0.300, precision is 5: -0.30000
value is 1.995 , precision is 2: 2.00

========== HalfOdd ==========
value is 0.00 , precision is 1: 0.0
value is 0.1 , precision is 5: 0.10000
value is -0.300, precision is 5: -0.30000
value is 1.995 , precision is 2: 1.99

========== TowardsZero ==========
value is 0.00 , precision is 1: 0.0
value is 0.1 , precision is 5: 0.10000
value is -0.300, precision is 5: -0.30000
value is 1.995 , precision is 2: 1.99

========== AwayFromZero ==========
value is 0.00 , precision is 1: 0.0
value is 0.1 , precision is 5: 0.10000
value is -0.300, precision is 5: -0.30000
value is 1.995 , precision is 2: 2.00

========== NegativeInfinity ==========
value is 0.00 , precision is 1: 0.0
value is 0.1 , precision is 5: 0.10000
value is -0.300, precision is 5: -0.30000
value is 1.995 , precision is 2: 1.99

========== PositiveInfinity ==========
value is 0.00 , precision is 1: 0.0
value is 0.1 , precision is 5: 0.10000
value is -0.300, precision is 5: -0.30000
value is 1.995 , precision is 2: 2.00
11 changes: 3 additions & 8 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,8 @@ static php_stream_filter_status_t php_iconv_stream_filter_do_filter(
if (php_iconv_stream_filter_append_bucket(self, stream, filter,
buckets_out, bucket->buf, bucket->buflen, &consumed,
php_stream_is_persistent(stream)) != SUCCESS) {
goto out_failure;
php_stream_bucket_delref(bucket);
return PSFS_ERR_FATAL;
}

php_stream_bucket_delref(bucket);
Expand All @@ -2545,7 +2546,7 @@ static php_stream_filter_status_t php_iconv_stream_filter_do_filter(
if (php_iconv_stream_filter_append_bucket(self, stream, filter,
buckets_out, NULL, 0, &consumed,
php_stream_is_persistent(stream)) != SUCCESS) {
goto out_failure;
return PSFS_ERR_FATAL;
}
}

Expand All @@ -2554,12 +2555,6 @@ static php_stream_filter_status_t php_iconv_stream_filter_do_filter(
}

return PSFS_PASS_ON;

out_failure:
if (bucket != NULL) {
php_stream_bucket_delref(bucket);
}
return PSFS_ERR_FATAL;
}
/* }}} */

Expand Down
17 changes: 17 additions & 0 deletions ext/iconv/tests/gh17047.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
GH-17047 (UAF on iconv filter failure)
--EXTENSIONS--
iconv
--FILE--
<?php
$stream = fopen('php://temp', 'w+');
stream_filter_append($stream, 'convert.iconv.UTF-16BE.UTF-8');
stream_filter_append($stream, 'convert.iconv.UTF-16BE.UTF-16BE');
fputs($stream, 'test');
rewind($stream);
var_dump(stream_get_contents($stream));
fclose($stream);
?>
--EXPECTF--
Warning: stream_get_contents(): iconv stream filter ("UTF-16BE"=>"UTF-16BE"): invalid multibyte sequence in %s on line %d
string(0) ""
2 changes: 1 addition & 1 deletion ext/pdo_firebird/firebird_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /*
char errmsg[512];
const ISC_STATUS *s = H->isc_status;
fb_interpret(errmsg, sizeof(errmsg),&s);
zend_throw_exception_ex(php_pdo_get_exception(), H->isc_status[1], "SQLSTATE[%s] [%ld] %s",
zend_throw_exception_ex(php_pdo_get_exception(), H->isc_status[1], "SQLSTATE[%s] [%" PRIiPTR "] %s",
"HY000", H->isc_status[1], errmsg);
}

Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_firebird/tests/bug_15604.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $dbh = getDbConnection();

$dbh->exec('
recreate table t_bug_15604 (
id bigint not null,
id int not null,
a int not null,
b int,
constraint pk_bug_15604 primary key(id)
Expand Down
2 changes: 2 additions & 0 deletions ext/pdo_firebird/tests/bug_76448.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ sockets
--XLEAK--
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
See https://github.com/FirebirdSQL/firebird/issues/7849
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?>
--FILE--
<?php
require_once "payload_server.inc";
Expand Down
Loading