electronicarts / EASTL

EASTL stands for Electronic Arts Standard Template Library. It is an extensive and robust implementation that has an emphasis on high performance.
BSD 3-Clause "New" or "Revised" License
8.25k stars 941 forks source link

basic_string not resilient... #401

Open alsliahona opened 3 years ago

alsliahona commented 3 years ago

If an allocator returns nullptr, basic_string's constructor still attempts to copy to nullptr. NOTE: I only tested string, nothing else, the problem may be more wide-spread.

Instead of blindly copying data to a pointer returned by the allocator, there should be a check to ensure that the allocator did not return nullptr. Similarly the size/length of the container should not be adjusted until after verification that the allocation worked.

Where exceptions are supported an exception should be thrown on allocation failure. Where they are not, the object should become invalid, so that the validate() call after the constructor returns false.

image

alsliahona commented 3 years ago

Note that this was tested by simply constructing a string using a custom allocator that returns nullptr. Construction was like this: using mockwstring = eastl::basic_string<wchar_t, MockAllocator>; mockwstring wstrMockTest(L"This is a test!"); if (false == wstrMockTest.validate()) ...Handle out-of-memory condition <-- This line is never reached