-
Notifications
You must be signed in to change notification settings - Fork 2.6k
BUGFIX: crash when "content-length" > max_int #142
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
Conversation
|
@MannyClicks, thank you for the really good bug report! After ponder over your PR, I came to the conclusion that it should convert the Content-Length to So I am thinking to remove inline size_t get_header_value_size_t(const Headers &headers, const char *key, size_t def = 0)When it comes to the conversion from string to I'll let you know when it's ready. Thanks a lot! |
|
Also, I am thinking to add the length check with the actual size of |
|
Thanks for the kind words. I recommend not using size_t directly. This choice would clamp the range of content-length to 32bit on 32bit platforms. Any upload > 4gb would break the server. Also, I assume the STL throws an exception if you try to convert a string stream value exceeding the size_t range to a size_t. My PR guarantees an unsigned 64bit type on all platforms. |
|
@MannyClicks, thanks for the clear information. I now understand that (1) Can we use (2) Should we fix Here is my thought regarding it: The return value from Also Lines 822 to 838 in 07ed076
So I am thinking to change the type of Does it make sense to you? |
|
Sure, happy to help the project 👍 RE 1: yes, I would - but I didn't because from looking at the project style it didn't seem to me that you'd be using stdint.h types. uint64_t would be the correct type as per my explanation above. RE 2: I think it should only load a user set maximum into the buffer on 32bit platforms and keep the rest on the socket. However, you'd need to inform the user that another read is necessary. Keep in mind that 32bit processes have 4GB memory limits that many people forget these days. It will make the handling the stream much more difficult than on a 64bit platform. I think an OK'ish alternative for 32bit platforms is to just reject such a big request (which can be done naturally if what I propose next is implemented). A better alternative would be to only load the content from the stream in the request path handler setup in the server if the user wants to do. Then the user can build his own chunked stream. Another thing I noticed in our stress testing today, we have to reject streams if the content length exceeds a maximum size specified in the server instance. Otherwise, bad clients can create 40gb requests - effectively killing our process. BTW, one thing I dislike about the API is that we have std::string everywhere for data buffers. I would prefer std::vector<uint8_t> |
|
Thanks for the further explanation. I removed As for RE 2, I'll ponder over those options.
Thanks for the suggestions, too. I made corresponding tickets. (Of course, you are welcome to implement these. 😄) |
|
Sounds good. Expect another PR soon! 😄 |
Hello Yuji,
this PR fixes a bug that happens when the Content-Length > max_int.
This crash was verified and reproduced on MacOS.
Thanks for creating this nice library, very helpful for us. ❤️