Skip to content
Closed
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
23 changes: 19 additions & 4 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,23 +639,38 @@ static php_iconv_err_t _php_iconv_substr(smart_str *pretval,
}

if (len < 0) {
if ((len += (total_len - offset)) < 0) {
return PHP_ICONV_ERR_SUCCESS;
len += (total_len - offset);
if (len < 0) {
/* Argument 2 is offsetn and argument 1 is source string */
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
get_active_function_arg_name(2), get_active_function_arg_name(1));
len = 0;
}
}

if (offset < 0) {
if ((offset += total_len) < 0) {
return PHP_ICONV_ERR_SUCCESS;
offset += total_len;
if (offset < 0) {
/* Argument 2 is offsetn and argument 1 is source string */
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
get_active_function_arg_name(2), get_active_function_arg_name(1));
offset = 0;
}
}

if((size_t)len > total_len) {
// TODO Emit notice/ValueError
len = total_len;
}


if ((size_t)offset > total_len) {
/* Argument 2 is offsetn and argument 1 is source string */
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
get_active_function_arg_name(2), get_active_function_arg_name(1));
/* Return an empty string */
smart_str_appendl(pretval, "", 0);
smart_str_0(pretval);
return PHP_ICONV_ERR_SUCCESS;
}

Expand Down
18 changes: 13 additions & 5 deletions ext/iconv/tests/iconv_substr.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ bar("This is a test", 0, -100000);
bar("This is a test", -9, -100000);
var_dump(iconv("ISO-2022-JP", "EUC-JP", iconv_substr(iconv("EUC-JP", "ISO-2022-JP", "����ˤ��� ISO-2022-JP"), 3, 8, "ISO-2022-JP")));
?>
--EXPECT--
--EXPECTF--
666768696a6b6c
666768696a6b6c
a6a4a8a4aaa4ab
a4aba4ada4afa4b1a4b3a4b5a4b7
bool(false)
bool(false)

Notice: substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(0) ""

Notice: iconv_substr(): Argument #2 ($offset) is not contained in argument #1 ($str) in %s on line %d
string(0) ""
string(14) "This is a test"
string(14) "This is a test"
string(3) "est"
Expand All @@ -56,7 +60,11 @@ string(3) "est"
string(5) "This "
string(5) "This "
bool(false)

Notice: iconv_substr(): Argument #2 ($offset) is not contained in argument #1 ($str) in %s on line %d
string(0) ""
bool(false)
bool(false)
bool(false)

Notice: iconv_substr(): Argument #2 ($offset) is not contained in argument #1 ($str) in %s on line %d
string(0) ""
string(10) "���� ISO-2"
7 changes: 7 additions & 0 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,8 @@ PHP_FUNCTION(mb_substr)
} else if (-from < mblen) {
real_from = mblen + from;
} else {
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
get_active_function_arg_name(2), get_active_function_arg_name(1));
real_from = 0;
}

Expand All @@ -2173,6 +2175,7 @@ PHP_FUNCTION(mb_substr)
} else if (real_from < mblen && -len < mblen - real_from) {
real_len = (mblen - real_from) + len;
} else {
// TODO Emit notice?
real_len = 0;
}

Expand Down Expand Up @@ -2218,6 +2221,8 @@ PHP_FUNCTION(mb_strcut)
if (from < 0) {
from = string.len + from;
if (from < 0) {
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
get_active_function_arg_name(2), get_active_function_arg_name(1));
from = 0;
}
}
Expand All @@ -2233,6 +2238,8 @@ PHP_FUNCTION(mb_strcut)
}

if (from > string.len) {
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
get_active_function_arg_name(2), get_active_function_arg_name(1));
RETURN_EMPTY_STRING();
}

Expand Down
4 changes: 3 additions & 1 deletion ext/mbstring/tests/bug49354.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ var_dump(mb_strcut($crap, 12, 100, 'UTF-8'));
var_dump(mb_strcut($crap, 13, 100, 'UTF-8'));

?>
--EXPECT--
--EXPECTF--
string(12) "AåBäCöDü"
string(11) "åBäCöDü"
string(11) "åBäCöDü"
string(9) "BäCöDü"
string(0) ""

Notice: mb_strcut(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(0) ""
6 changes: 5 additions & 1 deletion ext/mbstring/tests/mb_strcut.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ print MBStringChars(mb_strcut($utf16le, 1, 3, 'UTF-16LE'), 'UTF-16LE') . "\n";
print MBStringChars(mb_strcut($utf16le, 1, 4, 'UTF-16LE'), 'UTF-16LE') . "\n";

?>
--EXPECT--
--EXPECTF--
== EUC-JP ==
[a4ce cab8]
[a4b3 a4ce]
[30 31 32 33 a4b3 a4ce cab8 bbfa cef3 a4cf c6fc cbdc b8ec a4c7 a4b9 a1a3 45 55 43 2d 4a 50 a4f2 bbc8 a4c3 a4c6 a4a4 a4de a4b9 a1a3 c6fc cbdc b8ec a4cf cccc c5dd bdad a4a4 a1a3]

Notice: mb_strcut(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
OK

Notice: mb_strcut(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
OK
== UTF-8 ==
[]
Expand Down
4 changes: 3 additions & 1 deletion ext/mbstring/tests/mb_substr.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ $str = mb_substr($euc_jp, -100, 10,'EUC-JP');
($str !== "") ? print "4 OK: ".bin2hex($str)."\n" : print "NG: ".bin2hex($str)."\n";

?>
--EXPECT--
--EXPECTF--
1: c6fccbdcb8eca4c7a4b9a1a34555432d
2: 30313233a4b3a4cecab8bbfacef3a4cfc6fccbdcb8eca4c7a4b9a1a34555432d4a50a4f2bbc8a4c3a4c6a4a4a4dea4b9a1a3c6fccbdcb8eca4cfccccc5ddbdada4a4a1a3
3 OK

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
4 OK: 30313233a4b3a4cecab8bbfacef3a4cf
18 changes: 17 additions & 1 deletion ext/mbstring/tests/mb_substr_variation4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,47 @@ for ($i = -60; $i <= 60; $i += 10) {

echo "Done";
?>
--EXPECT--
--EXPECTF--
*** Testing mb_substr() : usage variations ***

**-- Offset is: -60 --**
-- ASCII String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(8) "K0lzIA=="
--Multibyte String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(16) "5pel5pys6Kqe44OG"

**-- Offset is: -50 --**
-- ASCII String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(8) "K0lzIA=="
--Multibyte String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(16) "5pel5pys6Kqe44OG"

**-- Offset is: -40 --**
-- ASCII String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(8) "K0lzIA=="
--Multibyte String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(16) "5pel5pys6Kqe44OG"

**-- Offset is: -30 --**
-- ASCII String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(8) "K0lzIA=="
--Multibyte String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(16) "5pel5pys6Kqe44OG"

**-- Offset is: -20 --**
Expand Down
18 changes: 17 additions & 1 deletion ext/mbstring/tests/mb_substr_variation6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,47 @@ for ($i = -60; $i <= 60; $i += 10) {

echo "Done";
?>
--EXPECT--
--EXPECTF--
*** Testing mb_substr() : usage variations ***

**-- Offset is: -60 --**
-- ASCII String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(8) "2b497320"
--Multibyte String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(24) "e697a5e69cace8aa9ee38386"

**-- Offset is: -50 --**
-- ASCII String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(8) "2b497320"
--Multibyte String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(24) "e697a5e69cace8aa9ee38386"

**-- Offset is: -40 --**
-- ASCII String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(8) "2b497320"
--Multibyte String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(24) "e697a5e69cace8aa9ee38386"

**-- Offset is: -30 --**
-- ASCII String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(8) "2b497320"
--Multibyte String --

Notice: mb_substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
string(24) "e697a5e69cace8aa9ee38386"

**-- Offset is: -20 --**
Expand Down
6 changes: 0 additions & 6 deletions ext/opcache/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,12 +968,6 @@ static inline int ct_eval_func_call(
return FAILURE;
}
/* pass */
} else if (zend_string_equals_literal(name, "substr")) {
if (Z_TYPE_P(args[0]) != IS_STRING
|| Z_TYPE_P(args[1]) != IS_LONG) {
return FAILURE;
}
/* pass */
} else if (zend_string_equals_literal(name, "pow")) {
if ((Z_TYPE_P(args[0]) != IS_LONG && Z_TYPE_P(args[0]) != IS_DOUBLE)
|| (Z_TYPE_P(args[1]) != IS_LONG && Z_TYPE_P(args[1]) != IS_DOUBLE)) {
Expand Down
8 changes: 4 additions & 4 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ function bin2hex(string $data): string {}

function hex2bin(string $data): string|false {}

function strspn(string $str, string $mask, int $start = 0, ?int $len = null): int|false {}
function strspn(string $str, string $mask, int $start = 0, ?int $len = null): int {}

function strcspn(string $str, string $mask, int $start = 0, ?int $len = null): int|false {}
function strcspn(string $str, string $mask, int $start = 0, ?int $len = null): int {}

#if HAVE_NL_LANGINFO
function nl_langinfo(int $item): string|false {}
Expand Down Expand Up @@ -610,7 +610,7 @@ function chunk_split(string $str, int $chunklen = 76, string $ending = "\r\n"):

function substr(string $str, int $start, ?int $length = null): string|false {}

function substr_replace(array|string $str, array|string $replace, array|int $start, array|int|null $length = null): string|array|false {}
function substr_replace(array|string $str, array|string $replace, array|int $start, array|int|null $length = null): string|array {}

function quotemeta(string $str): string {}

Expand Down Expand Up @@ -688,7 +688,7 @@ function str_split(string $str, int $split_length = 1): array {}

function strpbrk(string $haystack, string $char_list): string|false {}

function substr_compare(string $main_str, string $str, int $offset, ?int $length = null, bool $case_insensitivity = false): int|false {}
function substr_compare(string $main_str, string $str, int $offset, ?int $length = null, bool $case_insensitivity = false): int {}

function utf8_encode(string $data): string {}

Expand Down
8 changes: 4 additions & 4 deletions ext/standard/basic_functions_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 0224dc521c4a8bd49fbcfd26cddb01a2e571cf74 */
* Stub hash: 3937e2a532217fd78bc2ec94014a86a3e570d001 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
Expand Down Expand Up @@ -807,7 +807,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hex2bin, 0, 1, MAY_BE_STRING|MAY
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strspn, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_strspn, 0, 2, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, mask, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0")
Expand Down Expand Up @@ -930,7 +930,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr, 0, 2, MAY_BE_STRING|MAY_
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr_replace, 0, 3, MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr_replace, 0, 3, MAY_BE_STRING|MAY_BE_ARRAY)
ZEND_ARG_TYPE_MASK(0, str, MAY_BE_ARRAY|MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_MASK(0, replace, MAY_BE_ARRAY|MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_MASK(0, start, MAY_BE_ARRAY|MAY_BE_LONG, NULL)
Expand Down Expand Up @@ -1082,7 +1082,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strpbrk, 0, 2, MAY_BE_STRING|MAY
ZEND_ARG_TYPE_INFO(0, char_list, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr_compare, 0, 3, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_substr_compare, 0, 3, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, main_str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
Expand Down
Loading