mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Fix issues reported by oss-fuzz (#729)
* Fix oss-fuzz issue #26529 * Add test for oss-fuzz issue #26598 * Fix oss-fuzz issue #26632 * Revert change and add new test cases
This commit is contained in:
parent
17428a8fbf
commit
72b81badad
2 changed files with 25 additions and 3 deletions
|
@ -3171,9 +3171,10 @@ get_range_offset_and_length(const Request &req, size_t content_length,
|
|||
r.second = slen - 1;
|
||||
}
|
||||
|
||||
if (r.second == -1) { r.second = slen - 1; }
|
||||
|
||||
return std::make_pair(r.first, r.second - r.first + 1);
|
||||
if (r.second == -1) {
|
||||
r.second = slen - 1;
|
||||
}
|
||||
return std::make_pair(r.first, static_cast<size_t>(r.second - r.first) + 1);
|
||||
}
|
||||
|
||||
inline std::string make_content_range_header_field(size_t offset, size_t length,
|
||||
|
|
21
test/test.cc
21
test/test.cc
|
@ -1930,6 +1930,15 @@ TEST_F(ServerTest, GetStreamedWithRangeError) {
|
|||
EXPECT_EQ(416, res->status);
|
||||
}
|
||||
|
||||
//Tests long long overflow.
|
||||
TEST_F(ServerTest, GetRangeWithMaxLongLength) {
|
||||
auto res = cli_.Get("/with-range",{{"Range", "bytes=0-9223372036854775807"}});
|
||||
EXPECT_EQ(206, res->status);
|
||||
EXPECT_EQ("7", res->get_header_value("Content-Length"));
|
||||
EXPECT_EQ(true, res->has_header("Content-Range"));
|
||||
EXPECT_EQ(std::string("abcdefg"), res->body);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, GetStreamedWithRangeMultipart) {
|
||||
auto res =
|
||||
cli_.Get("/streamed-with-range", {{make_range_header({{1, 2}, {4, 5}})}});
|
||||
|
@ -2012,6 +2021,12 @@ TEST_F(ServerTest, GetWithRange4) {
|
|||
EXPECT_EQ(std::string("fg"), res->body);
|
||||
}
|
||||
|
||||
//TEST_F(ServerTest, GetWithRangeOffsetGreaterThanContent) {
|
||||
// auto res = cli_.Get("/with-range", {{make_range_header({{10000, 20000}})}});
|
||||
// ASSERT_TRUE(res);
|
||||
// EXPECT_EQ(416, res->status);
|
||||
//}
|
||||
|
||||
TEST_F(ServerTest, GetWithRangeMultipart) {
|
||||
auto res = cli_.Get("/with-range", {{make_range_header({{1, 2}, {4, 5}})}});
|
||||
ASSERT_TRUE(res);
|
||||
|
@ -2021,6 +2036,12 @@ TEST_F(ServerTest, GetWithRangeMultipart) {
|
|||
EXPECT_EQ(269, res->body.size());
|
||||
}
|
||||
|
||||
//TEST_F(ServerTest, GetWithRangeMultipartOffsetGreaterThanContent) {
|
||||
// auto res = cli_.Get("/with-range", {{make_range_header({{-1, 2}, {10000, 30000}})}});
|
||||
// ASSERT_TRUE(res);
|
||||
// EXPECT_EQ(416, res->status);
|
||||
//}
|
||||
|
||||
TEST_F(ServerTest, GetStreamedChunked) {
|
||||
auto res = cli_.Get("/streamed-chunked");
|
||||
ASSERT_TRUE(res);
|
||||
|
|
Loading…
Reference in a new issue