diff --git a/ext/standard/tests/http/request_parse_body/multipart_after_startup_parse.phpt b/ext/standard/tests/http/request_parse_body/multipart_after_startup_parse.phpt new file mode 100644 index 000000000000..0b3976ad6922 --- /dev/null +++ b/ext/standard/tests/http/request_parse_body/multipart_after_startup_parse.phpt @@ -0,0 +1,42 @@ +--TEST-- +request_parse_body() keeps files uploaded during startup parsing +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------84000087610663814162942123332 +-----------------------------84000087610663814162942123332 +Content-Disposition: form-data; name="file_name"; filename="original_file_name.txt" +Content-Type: text/plain + +file data +-----------------------------84000087610663814162942123332-- +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +bool(true) +string(9) "file data" diff --git a/ext/standard/tests/http/request_parse_body/multipart_twice.phpt b/ext/standard/tests/http/request_parse_body/multipart_twice.phpt new file mode 100644 index 000000000000..27b6e58f94b8 --- /dev/null +++ b/ext/standard/tests/http/request_parse_body/multipart_twice.phpt @@ -0,0 +1,45 @@ +--TEST-- +request_parse_body() called twice keeps files uploaded by the first call +--ENV-- +REQUEST_METHOD=PUT +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------84000087610663814162942123332 +-----------------------------84000087610663814162942123332 +Content-Disposition: form-data; name="file_name"; filename="original_file_name.txt" +Content-Type: text/plain + +file data +-----------------------------84000087610663814162942123332-- +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +bool(true) +string(9) "file data" diff --git a/main/rfc1867.c b/main/rfc1867.c index 39733e52c477..e7c228a79be4 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -694,7 +694,6 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) size_t array_len = 0; int64_t total_bytes = 0, max_file_size = 0; int skip_upload = 0, anonymous_index = 0; - HashTable *uploaded_files = NULL; multipart_buffer *mbuff; zval *array_ptr = (zval *) arg; bool throw_exceptions = SG(request_parse_body_context).throw_exceptions; @@ -792,9 +791,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* Initialize $_FILES[] */ zend_hash_init(&PG(rfc1867_protected_variables), 8, NULL, NULL, 0); - ALLOC_HASHTABLE(uploaded_files); - zend_hash_init(uploaded_files, 8, NULL, free_filename, 0); - SG(rfc1867_uploaded_files) = uploaded_files; + /* request_parse_body() may parse the body again, keep tracking earlier uploads */ + if (!SG(rfc1867_uploaded_files)) { + ALLOC_HASHTABLE(SG(rfc1867_uploaded_files)); + zend_hash_init(SG(rfc1867_uploaded_files), 8, NULL, free_filename, 0); + } if (Z_TYPE(PG(http_globals)[TRACK_VARS_FILES]) != IS_ARRAY) { /* php_auto_globals_create_files() might have already done that */