-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP: Fix the parsing ContentLength bug by http_parser #2851
Conversation
解决http_parser_execute,传入的buffer size包含了body的长度。导致即使包含了Content-Length长度,to_read又把parser->content_length重置为0. 修改为传入时,长度为http头的长度
Codecov Report
@@ Coverage Diff @@
## 4.0release #2851 +/- ##
==============================================
- Coverage 60.22% 60.21% -0.01%
==============================================
Files 121 121
Lines 51076 51083 +7
==============================================
+ Hits 30758 30759 +1
- Misses 20318 20324 +6 | Impacted Files | Coverage Δ | |' Translated to English while maintaining the markdown structure: '| Impacted Files | Coverage Δ | | Continue to review full report at Codecov.
'>
|
Using this to create an HTTP Callback Server, you can reproduce this issue:
|
When using httpcallback in srs4.0, occasionally there is a timeout issue when using the IP of the local network or 127 IP, but there is no problem when changing to the address of other servers. Colleague gdb debugging also has no problem. After debugging st recv data, it is found that there is no problem when receiving only the http head in a single packet. However, if the packet contains both the head and body, a timeout issue occurs. It is found that when parsing the header, if it contains both the http head and body, the content_length will be changed to 0, causing the problem.
|
6ac5da9
to
623ca78
Compare
👍 It should be because we were using the http_parser incorrectly, thanks for the patch.
|
Please @duiniuluantanqin take a look and see if we made any mistakes in calling the http parser, thank you.
|
After testing, the problem you mentioned does indeed exist. Thumbs up for your test case. However, the solution needs to be reconsidered.
|
p_header_tail指针为连续两个/r/n/r/n的第一个,进行判断时需要去掉2个字节
用content_length被置为0,退出时,将body长度赋值回去
@@ -136,7 +136,7 @@ srs_error_t SrsHttpParser::parse_message_imp(ISrsReader* reader) | |||
// @remark We shouldn't use on_body, because it only works for normal case, and losts the chunk header and length. | |||
// @see https://github.com/ossrs/srs/issues/1508 | |||
if (p_header_tail && buffer->bytes() < p_body_start) { | |||
for (const char* p = p_header_tail; p <= p_body_start - 4; p++) { | |||
for (const char* p = p_header_tail - 2; p <= p_body_start - 4; p++) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@@ -3258,6 +3258,7 @@ size_t http_parser_execute (http_parser *parser, | |||
p += to_read - 1; | |||
|
|||
if (parser->content_length == 0) { | |||
parser->content_length = p - body_mark + 1; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Thank you @mingyang0921 for reproducing and submitting the patch. The final solution can be found at #2888 (comment).
|
BUG
Solve http_parser_execute, the buffer size passed includes the length of the body. This causes parser->content_length to be reset to 0 even if the Content-Length length is included. Modify it so that when passed, the length is the length of the HTTP header.
Summary
Please describe the summary for this PR.
Details
Add more details about this PR.
TRANS_BY_GPT3