don't memcpy after failed alloc (#1315)

Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27675
This commit is contained in:
Paul Dreik 2020-11-21 07:52:24 +01:00 committed by GitHub
parent 0b39e3a6cf
commit 68a8004518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -65,6 +65,11 @@ inline padded_string::padded_string(const std::string & str_ ) noexcept
// note: do pass std::string_view arguments by value
inline padded_string::padded_string(std::string_view sv_) noexcept
: viable_size(sv_.size()), data_ptr(internal::allocate_padded_buffer(sv_.size())) {
if(simdjson_unlikely(!data_ptr)) {
//allocation failed or zero size
viable_size=0;
return;
}
if (sv_.size()) {
std::memcpy(data_ptr, sv_.data(), sv_.size());
}