Skip to content

Commit

Permalink
Cherry-pick 265870.553@safari-7616-branch (1393b61). https://bugs.web…
Browse files Browse the repository at this point in the history
…kit.org/show_bug.cgi?id=261220

    WTF::Vector cross-container overflow ASAN support
    https://bugs.webkit.org/show_bug.cgi?id=261220
    rdar://113692853

    Reviewed by David Kilzer.

    Added check in ASAN builds for container overflow

    * Source/WTF/wtf/Vector.h:
    (WTF::Malloc>::asanBufferSizeWillChangeTo):
    (WTF::Malloc>::uncheckedAppend):
    * Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:
    (TestWebKitAPI::TEST):

    Canonical link: https://commits.webkit.org/265870.553@safari-7616-branch
  • Loading branch information
abigailfox authored and aperezdc committed Oct 20, 2023
1 parent da56ace commit aa2b734
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Source/WTF/wtf/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,8 @@ inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::asa
if (!buffer())
return;

RELEASE_ASSERT_WITH_MESSAGE(newSize <= capacity(), "Attempt to expand size (%lu) beyond current capacity (%lu)", newSize, capacity());

// Change allowed range.
__sanitizer_annotate_contiguous_container(buffer(), endOfBuffer(), buffer() + size(), buffer() + newSize);
#else
Expand Down Expand Up @@ -1389,7 +1391,7 @@ ALWAYS_INLINE bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Mallo
if (!dataSize)
return true;

ASSERT(size() < capacity());
ASSERT_WITH_MESSAGE((Checked<size_t>(size()) + dataSize) <= capacity(), "uncheckedAppend() without expanding capacity");

size_t newSize = m_size + dataSize;
asanBufferSizeWillChangeTo(newSize);
Expand Down

0 comments on commit aa2b734

Please sign in to comment.