Skip to content

Commit

Permalink
Fix a UBSan warning in ObfuscatedFileUtilMemoryDelegate
Browse files Browse the repository at this point in the history
Due to a C language bug, memcpy is UB with NULL, 0. The C++ types avoid
this bug and are slightly more bounds-aware.

Bug: 1394755
Change-Id: Id9a152727914bff099d95f350040f02927c58961
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4986624
Auto-Submit: David Benjamin <[email protected]>
Commit-Queue: Austin Sullivan <[email protected]>
Reviewed-by: Austin Sullivan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1217115}
  • Loading branch information
davidben authored and Chromium LUCI CQ committed Oct 30, 2023
1 parent 99be2eb commit 21fcd5a
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/memory/raw_ptr_exclusion.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "net/base/io_buffer.h"
Expand Down Expand Up @@ -518,7 +519,9 @@ int ObfuscatedFileUtilMemoryDelegate::ReadFile(const base::FilePath& path,
if (buf_len > remaining)
buf_len = static_cast<int>(remaining);

memcpy(buf->data(), dp->entry->file_content.data() + offset, buf_len);
base::ranges::copy(
base::span(dp->entry->file_content).subspan(offset, buf_len),
buf->data());

return buf_len;
}
Expand Down

0 comments on commit 21fcd5a

Please sign in to comment.