Skip to content

Commit a720468

Browse files
committed
Zend: Revert strict validation of invalid upload_max_filesize and post_max_size values
998bce0 is accidentally pushed directly to master as this should go to a PR branch. This commit revert that.
1 parent 998bce0 commit a720468

8 files changed

Lines changed: 32 additions & 153 deletions

File tree

‎NEWS‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ PHP NEWS
3232
surrounding property access). (timwolla)
3333
. Fixed GH-22422 (zend_arena layout mismatch leaked memory in separately
3434
built extensions under AddressSanitizer). (iliaal)
35-
. Added validation for invalid upload_max_filesize and post_max_size values
36-
(GH-14695). (Weilin Du)
3735
. TSRM: use local-exec TLS in PIE executables. (henderkes)
3836
. perf: make all static extensions use TSRMG_STATIC. (henderkes)
3937
. Fixed bug GH-22257 (type confusion in Exception::getTraceAsString()).

‎Zend/tests/zend_ini/gh14695.phpt‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎Zend/tests/zend_ini/gh14695_empty.phpt‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎Zend/zend_ini.c‎

Lines changed: 17 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,7 @@ static const char *zend_ini_consume_quantity_prefix(const char *const digits, co
614614
return digits_consumed;
615615
}
616616

617-
static zend_ulong zend_ini_parse_quantity_internal(
618-
const zend_string *value,
619-
zend_ini_parse_quantity_signed_result_t signed_result,
620-
zend_string **errstr,
621-
bool strict
622-
) /* {{{ */
617+
static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zend_ini_parse_quantity_signed_result_t signed_result, zend_string **errstr) /* {{{ */
623618
{
624619
char *digits_end = NULL;
625620
const char *str = ZSTR_VAL(value);
@@ -639,18 +634,6 @@ static zend_ulong zend_ini_parse_quantity_internal(
639634
while (digits < str_end && zend_is_whitespace(*(str_end-1))) {--str_end;}
640635

641636
if (digits == str_end) {
642-
if (strict) {
643-
if (ZSTR_LEN(value) == 0) {
644-
*errstr = zend_strpprintf(0, "Invalid quantity \"\": no valid leading digits");
645-
} else {
646-
smart_str_append_escaped(&invalid, ZSTR_VAL(value), ZSTR_LEN(value));
647-
smart_str_0(&invalid);
648-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no valid leading digits",
649-
ZSTR_VAL(invalid.s));
650-
smart_str_free(&invalid);
651-
}
652-
return 0;
653-
}
654637
*errstr = NULL;
655638
return 0;
656639
}
@@ -670,13 +653,8 @@ static zend_ulong zend_ini_parse_quantity_internal(
670653
smart_str_append_escaped(&invalid, ZSTR_VAL(value), ZSTR_LEN(value));
671654
smart_str_0(&invalid);
672655

673-
if (strict) {
674-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no valid leading digits",
675-
ZSTR_VAL(invalid.s));
676-
} else {
677-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility",
678-
ZSTR_VAL(invalid.s));
679-
}
656+
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility",
657+
ZSTR_VAL(invalid.s));
680658

681659
smart_str_free(&invalid);
682660
return 0;
@@ -712,12 +690,8 @@ static zend_ulong zend_ini_parse_quantity_internal(
712690
base = 2;
713691
break;
714692
default:
715-
if (strict) {
716-
*errstr = zend_strpprintf(0, "Invalid prefix \"0%c\"", digits[1]);
717-
} else {
718-
*errstr = zend_strpprintf(0, "Invalid prefix \"0%c\", interpreting as \"0\" for backwards compatibility",
719-
digits[1]);
720-
}
693+
*errstr = zend_strpprintf(0, "Invalid prefix \"0%c\", interpreting as \"0\" for backwards compatibility",
694+
digits[1]);
721695
return 0;
722696
}
723697
digits += 2;
@@ -728,13 +702,8 @@ static zend_ulong zend_ini_parse_quantity_internal(
728702
smart_str_append_escaped(&invalid, ZSTR_VAL(value), ZSTR_LEN(value));
729703
smart_str_0(&invalid);
730704

731-
if (strict) {
732-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no digits after base prefix",
733-
ZSTR_VAL(invalid.s));
734-
} else {
735-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no digits after base prefix, interpreting as \"0\" for backwards compatibility",
736-
ZSTR_VAL(invalid.s));
737-
}
705+
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no digits after base prefix, interpreting as \"0\" for backwards compatibility",
706+
ZSTR_VAL(invalid.s));
738707

739708
smart_str_free(&invalid);
740709
return 0;
@@ -775,13 +744,8 @@ static zend_ulong zend_ini_parse_quantity_internal(
775744
smart_str_append_escaped(&invalid, ZSTR_VAL(value), ZSTR_LEN(value));
776745
smart_str_0(&invalid);
777746

778-
if (strict) {
779-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no valid leading digits",
780-
ZSTR_VAL(invalid.s));
781-
} else {
782-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility",
783-
ZSTR_VAL(invalid.s));
784-
}
747+
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility",
748+
ZSTR_VAL(invalid.s));
785749

786750
smart_str_free(&invalid);
787751
return 0;
@@ -817,13 +781,8 @@ static zend_ulong zend_ini_parse_quantity_internal(
817781
smart_str_append_escaped(&chr, str_end-1, 1);
818782
smart_str_0(&chr);
819783

820-
if (strict) {
821-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": unknown multiplier \"%s\"",
822-
ZSTR_VAL(invalid.s), ZSTR_VAL(chr.s));
823-
} else {
824-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": unknown multiplier \"%s\", interpreting as \"%s\" for backwards compatibility",
825-
ZSTR_VAL(invalid.s), ZSTR_VAL(chr.s), ZSTR_VAL(interpreted.s));
826-
}
784+
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": unknown multiplier \"%s\", interpreting as \"%s\" for backwards compatibility",
785+
ZSTR_VAL(invalid.s), ZSTR_VAL(chr.s), ZSTR_VAL(interpreted.s));
827786

828787
smart_str_free(&invalid);
829788
smart_str_free(&interpreted);
@@ -856,13 +815,8 @@ static zend_ulong zend_ini_parse_quantity_internal(
856815
smart_str_append_escaped(&chr, str_end-1, 1);
857816
smart_str_0(&chr);
858817

859-
if (strict) {
860-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": invalid characters before multiplier \"%s\"",
861-
ZSTR_VAL(invalid.s), ZSTR_VAL(chr.s));
862-
} else {
863-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\", interpreting as \"%s%s\" for backwards compatibility",
864-
ZSTR_VAL(invalid.s), ZSTR_VAL(interpreted.s), ZSTR_VAL(chr.s));
865-
}
818+
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\", interpreting as \"%s%s\" for backwards compatibility",
819+
ZSTR_VAL(invalid.s), ZSTR_VAL(interpreted.s), ZSTR_VAL(chr.s));
866820

867821
smart_str_free(&invalid);
868822
smart_str_free(&interpreted);
@@ -879,13 +833,8 @@ static zend_ulong zend_ini_parse_quantity_internal(
879833
/* Not specifying the resulting value here because the caller may make
880834
* additional conversions. Not specifying the allowed range
881835
* because the caller may do narrower range checks. */
882-
if (strict) {
883-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": value is out of range",
884-
ZSTR_VAL(invalid.s));
885-
} else {
886-
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": value is out of range, using overflow result for backwards compatibility",
887-
ZSTR_VAL(invalid.s));
888-
}
836+
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": value is out of range, using overflow result for backwards compatibility",
837+
ZSTR_VAL(invalid.s));
889838

890839
smart_str_free(&invalid);
891840
smart_str_free(&interpreted);
@@ -901,25 +850,13 @@ static zend_ulong zend_ini_parse_quantity_internal(
901850

902851
ZEND_API zend_long zend_ini_parse_quantity(const zend_string *value, zend_string **errstr) /* {{{ */
903852
{
904-
return (zend_long) zend_ini_parse_quantity_internal(value, ZEND_INI_PARSE_QUANTITY_SIGNED, errstr, false);
853+
return (zend_long) zend_ini_parse_quantity_internal(value, ZEND_INI_PARSE_QUANTITY_SIGNED, errstr);
905854
}
906855
/* }}} */
907856

908857
ZEND_API zend_ulong zend_ini_parse_uquantity(const zend_string *value, zend_string **errstr) /* {{{ */
909858
{
910-
return zend_ini_parse_quantity_internal(value, ZEND_INI_PARSE_QUANTITY_UNSIGNED, errstr, false);
911-
}
912-
/* }}} */
913-
914-
ZEND_API zend_result zend_ini_parse_quantity_strict(const zend_string *value, zend_long *result, zend_string **errstr) /* {{{ */
915-
{
916-
zend_long retval = (zend_long) zend_ini_parse_quantity_internal(value, ZEND_INI_PARSE_QUANTITY_SIGNED, errstr, true);
917-
if (*errstr) {
918-
return FAILURE;
919-
}
920-
921-
*result = retval;
922-
return SUCCESS;
859+
return zend_ini_parse_quantity_internal(value, ZEND_INI_PARSE_QUANTITY_UNSIGNED, errstr);
923860
}
924861
/* }}} */
925862

@@ -1037,23 +974,6 @@ ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */
1037974
}
1038975
/* }}} */
1039976

1040-
ZEND_API ZEND_INI_MH(OnUpdateLongStrict) /* {{{ */
1041-
{
1042-
zend_long tmp;
1043-
zend_string *errstr;
1044-
if (UNEXPECTED(zend_ini_parse_quantity_strict(new_value, &tmp, &errstr) == FAILURE)) {
1045-
zend_error(E_WARNING, "Invalid \"%s\" setting. %s", ZSTR_VAL(entry->name), ZSTR_VAL(errstr));
1046-
zend_string_release(errstr);
1047-
return FAILURE;
1048-
}
1049-
1050-
zend_long *p = ZEND_INI_GET_ADDR();
1051-
*p = tmp;
1052-
1053-
return SUCCESS;
1054-
}
1055-
/* }}} */
1056-
1057977
ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
1058978
{
1059979
zend_long tmp = zend_ini_parse_quantity_warn(new_value, entry->name);

‎Zend/zend_ini.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ ZEND_API zend_long zend_ini_parse_quantity(const zend_string *value, zend_string
142142
*/
143143
ZEND_API zend_ulong zend_ini_parse_uquantity(const zend_string *value, zend_string **errstr);
144144

145-
/**
146-
* Strict variant of zend_ini_parse_quantity. Ill-formatted values fail instead
147-
* of returning a backwards-compatible interpretation.
148-
*/
149-
ZEND_API zend_result zend_ini_parse_quantity_strict(const zend_string *value, zend_long *result, zend_string **errstr);
150-
151145
ZEND_API zend_long zend_ini_parse_quantity_warn(const zend_string *value, zend_string *setting);
152146

153147
ZEND_API zend_ulong zend_ini_parse_uquantity_warn(const zend_string *value, zend_string *setting);
@@ -213,7 +207,6 @@ END_EXTERN_C()
213207
BEGIN_EXTERN_C()
214208
ZEND_API ZEND_INI_MH(OnUpdateBool);
215209
ZEND_API ZEND_INI_MH(OnUpdateLong);
216-
ZEND_API ZEND_INI_MH(OnUpdateLongStrict);
217210
ZEND_API ZEND_INI_MH(OnUpdateLongGEZero);
218211
ZEND_API ZEND_INI_MH(OnUpdateReal);
219212
/* char* versions */

‎ext/standard/http.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,17 @@ PHP_FUNCTION(http_build_query)
247247
}
248248
/* }}} */
249249

250-
static zend_result cache_request_parse_body_option(zval *option, const char *option_name, int cache_offset)
250+
static zend_result cache_request_parse_body_option(HashTable *options, zval *option, int cache_offset)
251251
{
252252
if (option) {
253253
zend_long result;
254254
ZVAL_DEREF(option);
255255
if (Z_TYPE_P(option) == IS_STRING) {
256256
zend_string *errstr;
257-
if (UNEXPECTED(zend_ini_parse_quantity_strict(Z_STR_P(option), &result, &errstr) == FAILURE)) {
258-
zend_value_error("Invalid \"%s\" value in $options argument: %s", option_name, ZSTR_VAL(errstr));
257+
result = zend_ini_parse_quantity(Z_STR_P(option), &errstr);
258+
if (errstr) {
259+
zend_error(E_WARNING, "%s", ZSTR_VAL(errstr));
259260
zend_string_release(errstr);
260-
return FAILURE;
261261
}
262262
} else if (Z_TYPE_P(option) == IS_LONG) {
263263
result = Z_LVAL_P(option);
@@ -290,7 +290,7 @@ static zend_result cache_request_parse_body_options(HashTable *options)
290290

291291
#define CHECK_OPTION(name) \
292292
if (zend_string_equals_literal_ci(key, #name)) { \
293-
if (cache_request_parse_body_option(value, #name, REQUEST_PARSE_BODY_OPTION_ ## name) == FAILURE) { \
293+
if (cache_request_parse_body_option(options, value, REQUEST_PARSE_BODY_OPTION_ ## name) == FAILURE) { \
294294
return FAILURE; \
295295
} \
296296
continue; \

‎ext/standard/tests/http/request_parse_body/multipart_options_invalid_quantity.phpt‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ request_parse_body() invalid quantity
33
--FILE--
44
<?php
55

6-
foreach (['1GB', ''] as $value) {
7-
try {
8-
request_parse_body(options: [
9-
'upload_max_filesize' => $value,
10-
]);
11-
} catch (Throwable $e) {
12-
echo get_class($e), ': ', $e->getMessage(), "\n";
13-
}
6+
try {
7+
request_parse_body(options: [
8+
'upload_max_filesize' => '1GB',
9+
]);
10+
} catch (Throwable $e) {
11+
echo get_class($e), ': ', $e->getMessage(), "\n";
1412
}
1513

1614
?>
1715
--EXPECTF--
18-
ValueError: Invalid "upload_max_filesize" value in $options argument: Invalid quantity "1GB": unknown multiplier "B"
19-
ValueError: Invalid "upload_max_filesize" value in $options argument: Invalid quantity "": no valid leading digits
16+
Warning: Invalid quantity "1GB": unknown multiplier "B", interpreting as "1" for backwards compatibility in %s on line %d
17+
RequestParseBodyException: Request does not provide a content type

‎main/main.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ PHP_INI_BEGIN()
845845
STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_ALL, OnUpdateBaseDir, open_basedir, php_core_globals, core_globals)
846846

847847
STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
848-
STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongStrict, upload_max_filesize, php_core_globals, core_globals)
849-
STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongStrict, post_max_size, sapi_globals_struct,sapi_globals)
848+
STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
849+
STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, post_max_size, sapi_globals_struct,sapi_globals)
850850
STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
851851
STD_PHP_INI_ENTRY("max_input_nesting_level", "64", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_nesting_level, php_core_globals, core_globals)
852852
STD_PHP_INI_ENTRY("max_input_vars", "1000", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_vars, php_core_globals, core_globals)

0 commit comments

Comments
 (0)