googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Enabling AddressSanitizer under MSVC gives errors on the simplest of tests

Open laurynas-biveinis opened this issue 1 year ago • 0 comments

Describe the bug

Enabling AddressSanitizer under MSVC gives errors on the simplest of tests

=================================================================
==12428==ERROR: AddressSanitizer: unknown-crash on address 0x12abcb4a01f9 at pc 0x7ff650f173ca bp 0x00fc4f0ff020 sp 0x00fc4f0fe7c0
READ of size 18 at 0x12abcb4a01f9 thread T0
    #0 0x7ff650f173f9 in __asan_wrap_strlen D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_common_interceptors.inc:375
    #1 0x7ff650edadc2 in std::_Narrow_char_traits<char, int>::length(char const *const) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\xstring:401
    #2 0x7ff650ec842a in std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>(char const *const) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\xstring:2622
    #3 0x7ff650f56adf in testing::internal::UnitTestImpl::FilterTests(enum testing::internal::UnitTestImpl::ReactionToSharding) C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\3rd_party\googletest\googletest\src\gtest.cc:6064
    #4 0x7ff650f555b5 in testing::internal::UnitTestImpl::RunAllTests(void) C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\3rd_party\googletest\googletest\src\gtest.cc:5783
    #5 0x7ff650f9d5fd in testing::internal::HandleSehExceptionsInMethodIfSupported<class testing::internal::UnitTestImpl, bool>(class testing::internal::UnitTestImpl *, bool (__cdecl testing::internal::UnitTestImpl::*)(void), char const *) C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\3rd_party\googletest\googletest\src\gtest.cc:2586
    #6 0x7ff650f9d2d7 in testing::internal::HandleExceptionsInMethodIfSupported<class testing::internal::UnitTestImpl, bool>(class testing::internal::UnitTestImpl *, bool (__cdecl testing::internal::UnitTestImpl::*)(void), char const *) C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\3rd_party\googletest\googletest\src\gtest.cc:2637
    #7 0x7ff650f46dbe in testing::UnitTest::Run(void) C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\3rd_party\googletest\googletest\src\gtest.cc:5443
    #8 0x7ff651162860 in RUN_ALL_TESTS(void) C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\3rd_party\googletest\googletest\include\gtest\gtest.h:2293
    #9 0x7ff651162843 in main C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\3rd_party\googletest\googletest\src\gtest_main.cc:51
    #10 0x7ff65109e1b8 in invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
    #11 0x7ff65109e10d in __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    #12 0x7ff65109dfcd in __scrt_common_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:330
    #13 0x7ff65109e22d in mainCRTStartup D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:16
    #14 0x7ff9439054df  (C:\WINDOWS\System32\KERNEL32.DLL+0x1800154df)
    #15 0x7ff9449e485a  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x18000485a)

0x12abcb4a01f9 is located 57 bytes inside of 280-byte region [0x12abcb4a01c0,0x12abcb4a02d8)
allocated by thread T0 here:
    #0 0x7ff651054c3a in operator new(unsigned __int64) D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\asan\asan_win_new_scalar_thunk.cpp:41
    #1 0x7ff650f39983 in testing::internal::MakeAndRegisterTestInfo(char const *, char const *, char const *, char const *, struct testing::internal::CodeLocation, void const *, void (__cdecl *)(void), void (__cdecl *)(void), class testing::internal::TestFactoryBase *) C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\3rd_party\googletest\googletest\src\gtest.cc:2756
    #2 0x7ff650ec13a1 in `dynamic initializer for 'QSBRPtr_CopyCtor_Test::test_info_'' C:\Users\Laurynas\source\repos\laurynas-biveinis\unodb\test\test_qsbr_ptr.cpp:3
    #3 0x7ff651122e58 in _initterm minkernel\crts\ucrt\src\appcrt\startup\initterm.cpp:21
    #4 0x7ff65109e068 in __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:256
    #5 0x7ff65109dfcd in __scrt_common_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:330
    #6 0x7ff65109e22d in mainCRTStartup D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:16
    #7 0x7ff9439054df  (C:\WINDOWS\System32\KERNEL32.DLL+0x1800154df)
    #8 0x7ff9449e485a  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x18000485a)

SUMMARY: AddressSanitizer: unknown-crash D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_common_interceptors.inc:375 in __asan_wrap_strlen
Shadow bytes around the buggy address:
  0x04dd44b13fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x04dd44b13ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x04dd44b14000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x04dd44b14010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x04dd44b14020: 00 00 00 00 00 00 00 00 04 fa fa fa fa fa fa fa
=>0x04dd44b14030: fa fa fa fa fa fa fa fa 00 00 fc 00 00 00 00[01]
  0x04dd44b14040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x04dd44b14050: 00 00 00 00 00 00 00 00 00 00 00 fa fa fa fa fa
  0x04dd44b14060: fa fa fa fa fa fa fa fa 00 00 00 fc 00 00 00 00
  0x04dd44b14070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x04dd44b14080: 00 00 00 00 00 00 00 00 00 00 fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==12428==ABORTING

Steps to reproduce the bug

The minimal project structure as follows: test/test_qsbr_ptr.cpp:

#include <gtest/gtest.h>

TEST(QSBRPtr, CopyCtor) {
}

CMakeLists.txt:

string(APPEND CMAKE_CXX_FLAGS " /fsanitize=address")

string(REGEX REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")

add_subdirectory(3rd_party/googletest)

enable_testing()

add_executable(test_qsbr_ptr test/test_qsbr_ptr.cpp)
target_link_libraries(test_qsbr_ptr PRIVATE gtest_main)

3rd_party/googletest is a submodule checked out at either v1.12.1 or today's head (https://github.com/google/googletest/commit/0e0d9feefab1b51aaab9dfd70132e93c0b6964e5)

Does the bug persist in the most recent commit?

Yes, tested with https://github.com/google/googletest/commit/0e0d9feefab1b51aaab9dfd70132e93c0b6964e5

What operating system and version are you using?

Windows 11

What compiler and version are you using?

MSVC 17.3.3

What build system are you using?

CMake integrated to MSVC 17.3.3

Additional context

This is a regression in either recent MSVC or Google Test version, as it worked with MSVC 17.2 with Google Test 1.11 and earlier versions.

laurynas-biveinis avatar Sep 02 '22 06:09 laurynas-biveinis