cppalliance / http_proto

HTTP/1 parsing and serialization algorithms using C++11
https://develop.http-proto.cpp.al/
Boost Software License 1.0
23 stars 10 forks source link

fix incorrect size calculation when headers are complete #96

Closed cmazakas closed 3 months ago

cmazakas commented 3 months ago

Fixing the flat_buffer has caused a latent implementation bug to surface in the parser tests. Namely:

{
    // Content-Length, in_place limit
    response_parser::config cfg;
    core::string_view const h =
        "HTTP/1.1 200 OK\r\n"
        "Content-Length: 10\r\n"
        "\r\n";
    cfg.headers.max_size = h.size();
    cfg.min_buffer = 3;
    check_in_place(cfg, true,
        error::in_place_overflow, false, {
        h, "1234567890" });
}

This test will pass when it should fail with the above in_place_overflow error. This is caused by an underflow on unsigned integers, which results in a wrap-around and n0 winds up being the unsigned equivalent of -33 which is actually quite large in unsigned.

The code most likely meant fb_.max_size() when it did this check and we've updated it to include an assertion for the purposes of saftey.

cppalliance-bot commented 3 months ago

Antora version: an automated preview of the documentation is available at https://96.http-proto.prtest.cppalliance.org/site/index.html

cppalliance-bot commented 3 months ago

GCOVR code coverage report https://96.http-proto.prtest.cppalliance.org/gcovr/index.html
LCOV code coverage report https://96.http-proto.prtest.cppalliance.org/genhtml/index.html Coverage Diff https://96.http-proto.prtest.cppalliance.org/gcovr/coverage_diff.txt

cppalliance-bot commented 3 months ago

Antora version: an automated preview of the documentation is available at https://96.http-proto.prtest.cppalliance.org/site/index.html

cppalliance-bot commented 3 months ago

GCOVR code coverage report https://96.http-proto.prtest.cppalliance.org/gcovr/index.html
LCOV code coverage report https://96.http-proto.prtest.cppalliance.org/genhtml/index.html Coverage Diff https://96.http-proto.prtest.cppalliance.org/gcovr/coverage_diff.txt

vinniefalco commented 3 months ago

@ashtum please review

cppalliance-bot commented 3 months ago

Antora version: an automated preview of the documentation is available at https://96.http-proto.prtest.cppalliance.org/site/index.html

cppalliance-bot commented 3 months ago

Antora version: an automated preview of the documentation is available at https://96.http-proto.prtest.cppalliance.org/site/index.html

vinniefalco commented 3 months ago

if its ready, merge it