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
12 changes: 6 additions & 6 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ jobs:
cd "amphp-$repository"
git rev-parse HEAD
php /usr/bin/composer install --no-progress --ignore-platform-req=php+
vendor/bin/phpunit
EXIT_CODE=$?
EXIT_CODE=0
vendor/bin/phpunit || EXIT_CODE=$?
echo -e "\n::endgroup::"
if [ ${EXIT_CODE:-0} -gt 128 ]; then
X=1;
Expand Down Expand Up @@ -592,8 +592,8 @@ jobs:
cd "reactphp-$repository"
git rev-parse HEAD
php /usr/bin/composer install --no-progress --ignore-platform-req=php+
vendor/bin/phpunit
EXIT_CODE=$?
EXIT_CODE=0
vendor/bin/phpunit || EXIT_CODE=$?
echo -e "\n::endgroup::"
if [ $[EXIT_CODE:-0} -gt 128 ]; then
X=1;
Expand Down Expand Up @@ -629,8 +629,8 @@ jobs:
X=0
for component in $(find src/Symfony -mindepth 2 -type f -name phpunit.xml.dist -printf '%h\n'); do
echo "::group::$component"
php ./phpunit $component --exclude-group tty --exclude-group benchmark --exclude-group intl-data --exclude-group transient --exclude-group skip
EXIT_CODE=$?
EXIT_CODE=0
php ./phpunit $component --exclude-group tty --exclude-group benchmark --exclude-group intl-data --exclude-group transient --exclude-group skip || EXIT_CODE=$?
echo -e "\n::endgroup::"
if [ ${EXIT_CODE:-0} -gt 128 ]; then
X=1;
Expand Down
25 changes: 25 additions & 0 deletions ext/calendar/calendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ PHP_FUNCTION(cal_days_in_month)
RETURN_THROWS();
}

if (UNEXPECTED(month <= 0 || month > INT32_MAX - 1)) {
zend_argument_value_error(2, "must be between 1 and %d", INT32_MAX - 1);
RETURN_THROWS();
}

if (UNEXPECTED(year > INT32_MAX - 1)) {
zend_argument_value_error(3, "must be less than %d", INT32_MAX - 1);
RETURN_THROWS();
}

calendar = &cal_conversion_table[cal];

sdn_start = calendar->to_jd(year, month, 1);
Expand Down Expand Up @@ -242,6 +252,21 @@ PHP_FUNCTION(cal_to_jd)
RETURN_THROWS();
}

if (UNEXPECTED(month <= 0 || month > INT32_MAX - 1)) {
zend_argument_value_error(2, "must be between 1 and %d", INT32_MAX - 1);
RETURN_THROWS();
}

if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(day))) {
zend_argument_value_error(3, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}

if (UNEXPECTED(year > INT32_MAX - 1)) {
zend_argument_value_error(4, "must be less than %d", INT32_MAX - 1);
RETURN_THROWS();
}

RETURN_LONG(cal_conversion_table[cal].to_jd(year, month, day));
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion ext/calendar/tests/cal_days_in_month_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
echo "{$ex->getMessage()}\n";
}
try{
cal_days_in_month(CAL_GREGORIAN,0, 2009);
cal_days_in_month(CAL_GREGORIAN,20, 2009);
} catch (ValueError $ex) {
echo "{$ex->getMessage()}\n";
}
Expand Down
61 changes: 61 additions & 0 deletions ext/calendar/tests/gh19371.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--TEST--
GH-19371 (integer overflow in calendar.c)
--SKIPIF--
<?php if (PHP_INT_SIZE !== 8) die("skip only for 64-bit"); ?>
--EXTENSIONS--
calendar
--FILE--
<?php

try {
echo cal_days_in_month(CAL_GREGORIAN, 12, PHP_INT_MAX);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_days_in_month(CAL_GREGORIAN, PHP_INT_MIN, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_days_in_month(CAL_GREGORIAN, PHP_INT_MAX, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
echo cal_to_jd(CAL_GREGORIAN, PHP_INT_MIN, 1, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_to_jd(CAL_GREGORIAN, PHP_INT_MAX, 1, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_to_jd(CAL_GREGORIAN, 1, PHP_INT_MIN, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_to_jd(CAL_GREGORIAN, 1, PHP_INT_MAX, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_to_jd(CAL_GREGORIAN, 1, 1, PHP_INT_MAX);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
cal_days_in_month(): Argument #3 ($year) must be less than 2147483646
cal_days_in_month(): Argument #2 ($month) must be between 1 and 2147483646
cal_days_in_month(): Argument #2 ($month) must be between 1 and 2147483646
cal_to_jd(): Argument #2 ($month) must be between 1 and 2147483646
cal_to_jd(): Argument #2 ($month) must be between 1 and 2147483646
cal_to_jd(): Argument #3 ($day) must be between -2147483648 and 2147483647
cal_to_jd(): Argument #3 ($day) must be between -2147483648 and 2147483647
cal_to_jd(): Argument #4 ($year) must be less than 2147483646
23 changes: 20 additions & 3 deletions ext/intl/converter/converter.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "../intl_error.h"
#include "../intl_common.h"
#include "converter_arginfo.h"
#include "php_intl.h"

typedef struct _php_converter_object {
UConverter *src, *dest;
Expand Down Expand Up @@ -370,7 +371,10 @@ static bool php_converter_set_encoding(php_converter_object *objval,
/* Should never happen */
actual_encoding = "(unknown)";
}
php_error_docref(NULL, E_WARNING, "Ambiguous encoding specified, using %s", actual_encoding);
char *msg;
spprintf(&msg, 0, "Ambiguous encoding specified, using %s", actual_encoding);
intl_error_set(NULL, error, msg);
efree(msg);
} else if (U_FAILURE(error)) {
if (objval) {
THROW_UFAILURE(objval, error);
Expand Down Expand Up @@ -530,10 +534,23 @@ PHP_METHOD(UConverter, __construct) {
Z_PARAM_STRING_OR_NULL(src, src_len)
ZEND_PARSE_PARAMETERS_END();

php_converter_set_encoding(objval, &(objval->src), src, src_len );
php_converter_set_encoding(objval, &(objval->dest), dest, dest_len);
const bool old_use_exception = INTL_G(use_exceptions);
const zend_long old_error_level = INTL_G(error_level);
INTL_G(use_exceptions) = true;
INTL_G(error_level) = 0;
if (UNEXPECTED(!php_converter_set_encoding(objval, &(objval->src), src, src_len))) {
ZEND_ASSERT(EG(exception));
goto cleanup;
}
if (UNEXPECTED(!php_converter_set_encoding(objval, &(objval->dest), dest, dest_len))) {
ZEND_ASSERT(EG(exception));
goto cleanup;
}
php_converter_resolve_callback(&objval->to_cache, Z_OBJ_P(ZEND_THIS), ZEND_STRL("toUCallback"));
php_converter_resolve_callback(&objval->from_cache, Z_OBJ_P(ZEND_THIS), ZEND_STRL("fromUCallback"));
cleanup:
INTL_G(use_exceptions) = old_use_exception;
INTL_G(error_level) = old_error_level;
}
/* }}} */

Expand Down
2 changes: 1 addition & 1 deletion ext/intl/tests/bug75317.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Bug #75317 (UConverter::setDestinationEncoding changes source instead of destinatination)
Bug #75317 (UConverter::setDestinationEncoding changes source instead of destination)
--EXTENSIONS--
intl
--FILE--
Expand Down
15 changes: 9 additions & 6 deletions ext/intl/tests/timezone_createTimeZoneIDEnumeration_error.phpt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
--TEST--
IntlTimeZone::createTimeZoneIDEnumeration(): errors
IntlTimeZone::createTimeZoneIDEnumeration() invalid zone type
--EXTENSIONS--
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

var_dump(IntlTimeZone::createTimeZoneIDEnumeration(-1));
try {
var_dump(IntlTimeZone::createTimeZoneIDEnumeration(-1));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECTF--
Warning: IntlTimeZone::createTimeZoneIDEnumeration(): bad zone type in %s on line %d
bool(false)
--EXPECT--
ValueError: IntlTimeZone::createTimeZoneIDEnumeration(): Argument #1 ($type) must be one of IntlTimeZone::TYPE_ANY, IntlTimeZone::TYPE_CANONICAL, or IntlTimeZone::TYPE_CANONICAL_LOCATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
IntlTimeZone::createTimeZoneIDEnumeration() offset out of range
--EXTENSIONS--
intl
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
--FILE--
<?php

try {
var_dump(IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, '', PHP_INT_MAX));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
ValueError: IntlTimeZone::createTimeZoneIDEnumeration(): Argument #1 ($type) must be between -2147483648 and 2147483647
23 changes: 15 additions & 8 deletions ext/intl/tests/uconverter___construct_error.phpt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
--TEST--
Basic UConverter::convert() usage
--INI--
intl.error_level = E_WARNING
--EXTENSIONS--
intl
--FILE--
<?php
$c = new UConverter('utf-8', "\x80");
var_dump($c);
?>
--EXPECTF--
Warning: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR in %s on line %d
object(UConverter)#%d (0) {
try {
$c = new UConverter("\x80", 'utf-8');
var_dump($c);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$c = new UConverter('utf-8', "\x80");
var_dump($c);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
IntlException: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR
IntlException: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR
6 changes: 5 additions & 1 deletion ext/intl/tests/uconverter_bug66873.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ Bug #66873 - crash in UConverter with invalid encoding
intl
--FILE--
<?php
try {
$o = new UConverter(1, 1);
$o->toUCallback(1, 1, 1, $b);
var_dump($o->getErrorCode());
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
int(27)
IntlException: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR
14 changes: 7 additions & 7 deletions ext/intl/timezone/timezone_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration)

if (zoneType != UCAL_ZONE_TYPE_ANY && zoneType != UCAL_ZONE_TYPE_CANONICAL
&& zoneType != UCAL_ZONE_TYPE_CANONICAL_LOCATION) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "bad zone type");
RETURN_FALSE;
zend_argument_value_error(1, "must be one of IntlTimeZone::TYPE_ANY,"
" IntlTimeZone::TYPE_CANONICAL, or IntlTimeZone::TYPE_CANONICAL_LOCATION");
RETURN_THROWS();
}

if (!arg3isnull) {
if (UNEXPECTED(offset_arg < (zend_long)INT32_MIN || offset_arg > (zend_long)INT32_MAX)) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"offset out of bounds");
RETURN_FALSE;
if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(offset_arg))) {
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
offset = (int32_t)offset_arg;
offset = static_cast<int32_t>(offset_arg);
offsetp = &offset;
} //else leave offsetp NULL

Expand Down