Commit 871cebaf by Niels Lohmann

🚑 fix for #405

parent 8381cd60
...@@ -6871,6 +6871,12 @@ class basic_json ...@@ -6871,6 +6871,12 @@ class basic_json
{ {
throw std::out_of_range("len+offset out of range"); throw std::out_of_range("len+offset out of range");
} }
// last case: reading past the end of the vector
if (len + offset > size)
{
throw std::out_of_range("len+offset out of range");
}
} }
/*! /*!
......
...@@ -6871,6 +6871,12 @@ class basic_json ...@@ -6871,6 +6871,12 @@ class basic_json
{ {
throw std::out_of_range("len+offset out of range"); throw std::out_of_range("len+offset out of range");
} }
// last case: reading past the end of the vector
if (len + offset > size)
{
throw std::out_of_range("len+offset out of range");
}
} }
/*! /*!
......
...@@ -540,4 +540,11 @@ TEST_CASE("regression tests") ...@@ -540,4 +540,11 @@ TEST_CASE("regression tests")
CHECK(j.is_number_float()); CHECK(j.is_number_float());
CHECK(j.dump() == "1.66020696663386e+20"); CHECK(j.dump() == "1.66020696663386e+20");
} }
SECTION("issue #405 - Heap-buffer-overflow (OSS-Fuzz issue 342)")
{
// original test case
std::vector<uint8_t> vec {0x65, 0xf5, 0x0a, 0x48, 0x21};
CHECK_THROWS_AS(json::from_cbor(vec), std::out_of_range);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment