From 2cf0afd34ef80f06a83f85faaaf2aa6df3008beb Mon Sep 17 00:00:00 2001 From: MARiA so cute <33935209+NathanFreeman@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:22:41 +0800 Subject: [PATCH] [5.1]Fix bug #5168 (#5169) * Fix bug #5186 * Fix test --- tests/swoole_http_server/bug_5186.phpt | 47 ++++++++++++++++++++++++++ thirdparty/multipart_parser.c | 5 ++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/swoole_http_server/bug_5186.phpt diff --git a/tests/swoole_http_server/bug_5186.phpt b/tests/swoole_http_server/bug_5186.phpt new file mode 100644 index 00000000000..c6a89a874f2 --- /dev/null +++ b/tests/swoole_http_server/bug_5186.phpt @@ -0,0 +1,47 @@ +--TEST-- +swoole_http_server: 在使用hyperf3的时候遇到Context::parse_multipart_data()的提示 +--SKIPIF-- + +--FILE-- +parentFunc = function () use ($pm) { + run(function () use ($pm) { + $content = "POST / HTTP/1.1\r\nHost: 127.0.0.1:{$pm->getFreePort()}\r\nConnection: keep-alive\r\nContent-Length: 44\r\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundaryOldDnwBESVoBBtI5\r\nAccept-Encoding: gzip, deflate\r\n\r\n------WebKitFormBoundaryOldDnwBESVoBBtI5--\r\n\r\n"; + $client = new Client(SWOOLE_SOCK_TCP); + $client->connect('127.0.0.1', $pm->getFreePort(), 0.5); + $client->send($content); + $client->close(); + }); + echo "DONE\n"; + $pm->kill(); +}; + +$pm->childFunc = function () use ($pm) { + $http = new Server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE); + $http->set([ + 'log_file' => '/dev/null', + ]); + $http->on('workerStart', function () use ($pm) { + $pm->wakeup(); + }); + $http->on('request', function (Request $request, Response $response) use ($http) { + var_dump($request->files); + $response->end('Hello World'); + }); + $http->start(); +}; +$pm->childFirst(); +$pm->run(); +?> +--EXPECT-- +DONE +NULL diff --git a/thirdparty/multipart_parser.c b/thirdparty/multipart_parser.c index 4366da75103..8061de10699 100644 --- a/thirdparty/multipart_parser.c +++ b/thirdparty/multipart_parser.c @@ -203,7 +203,10 @@ ssize_t multipart_parser_execute(multipart_parser *p, const char *buf, size_t le case s_start_boundary: multipart_log_c("s_start_boundary"); if (p->index == p->boundary_length) { - if (c != CR) { + // https://github.com/swoole/swoole-src/issues/5168 + if (c == '-') { + p->state = s_part_data_final_hyphen; + } else if (c != CR) { ERROR_EXPECT(MPPE_BOUNDARY_END_NO_CRLF, CR); } p->index++;