Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TestHelper] Fix ODR violation that causes crash #1749

Merged
merged 1 commit into from
Jan 4, 2025

Conversation

neo1973
Copy link
Member

@neo1973 neo1973 commented Jan 2, 2025

Description

Fixes a problem with the One Definition Rule. This prevents the following crash when executing the tests:

stack trace
==208457==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x5020000212b8 at pc 0x5ccdf721f19e bp 0x7ffc1c32ecd0 sp 0x7ffc1c32ecc8
READ of size 8 at 0x5020000212b8 thread T0
    #0 0x5ccdf721f19d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_data() const /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/basic_string.h:228:28
    #1 0x5ccdf721fb78 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_is_local() const /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/basic_string.h:269:6
    #2 0x5ccdf721fab8 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/basic_string.h:287:7
    #3 0x5ccdf721ff48 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/basic_string.h:809:9
    #4 0x5ccdf730f648 in AESDecrypter::~AESDecrypter() src/test/TestHelper.h:84:35
    #5 0x5ccdf730f968 in AESDecrypter::~AESDecrypter() src/test/TestHelper.h:84:35
    #6 0x5ccdf7319744 in std::default_delete<IAESDecrypter>::operator()(IAESDecrypter*) const /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/unique_ptr.h:93:2
    #7 0x5ccdf73193fe in std::unique_ptr<IAESDecrypter, std::default_delete<IAESDecrypter>>::~unique_ptr() /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/unique_ptr.h:398:4
    #8 0x5ccdf730f71b in adaptive::CHLSTree::~CHLSTree() src/test/../parser/HLSTree.h:30:24
    #9 0x5ccdf730fd28 in HLSTestTree::~HLSTestTree() src/test/TestHelper.h:131:7
    #10 0x5ccdf730fd78 in HLSTestTree::~HLSTestTree() src/test/TestHelper.h:131:7
    #11 0x5ccdf72df9ea in HLSTreeTest::TearDown() src/test/TestHLSTree.cpp:29:5
    #12 0x7a29555638e9 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2638:27
    #13 0x7a29555638e9 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (.constprop.0) /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2674:52
    #14 0x7a295554f36e in testing::TestInfo::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2859:14
    #15 0x7a295554f553 in testing::TestSuite::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:3037:33
    #16 0x7a295554f553 in testing::TestSuite::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2991:6
    #17 0x7a295555b708 in testing::internal::UnitTestImpl::RunAllTests() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:5967:47
    #18 0x7a295555bd78 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2638:27
    #19 0x7a295555bd78 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2674:52
    #20 0x7a295555bd78 in testing::UnitTest::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:5546:55
    #21 0x5ccdf721c5d0 in RUN_ALL_TESTS() /usr/include/gtest/gtest.h:2334:73
    #22 0x5ccdf721be50 in main src/test/TestMain.cpp:20:10
    #23 0x7a2954f45e07 in __libc_start_call_main /usr/src/debug/glibc/glibc/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #24 0x7a2954f45ecb in __libc_start_main /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:360:3
    #25 0x5ccdf70e4464 in _start (/home/mark/Coding/Repos/inputstream.adaptive/build_clang_debug_sanitizer/src/test/inputstream.adaptive_test+0xf30464) (BuildId: 53a3fced4234a38f5911a78d952158d8708ef61b)

0x5020000212b8 is located 0 bytes after 8-byte region [0x5020000212b0,0x5020000212b8)
allocated by thread T0 here:
    #0 0x5ccdf7218f82 in operator new(unsigned long) (/home/mark/Coding/Repos/inputstream.adaptive/build_clang_debug_sanitizer/src/test/inputstream.adaptive_test+0x1064f82) (BuildId: 53a3fced4234a38f5911a78d952158d8708ef61b)
    #1 0x5ccdf74647e8 in std::__detail::_MakeUniq<AESDecrypter>::__single_object std::make_unique<AESDecrypter>() /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/unique_ptr.h:1076:30
    #2 0x5ccdf7426d2d in adaptive::CHLSTree::Configure(CHOOSER::IRepresentationChooser*, std::vector<std::basic_string_view<char, std::char_traits<char>>, std::allocator<std::basic_string_view<char, std::char_traits<char>>>>, std::basic_string_view<char, std::char_traits<char>>) src/parser/HLSTree.cpp:169:17
    #3 0x5ccdf72ddc3b in HLSTreeTest::OpenTestFileMaster(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>, std::vector<std::basic_string_view<char, std::char_traits<char>>, std::allocator<std::basic_string_view<char, std::char_traits<char>>>>) src/test/TestHLSTree.cpp:67:11
    #4 0x5ccdf72db255 in HLSTreeTest::OpenTestFileMaster(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>) src/test/TestHLSTree.cpp:42:12
    #5 0x5ccdf72b7144 in HLSTreeTest_CalculateSourceUrl_Test::TestBody() src/test/TestHLSTree.cpp:102:3
    #6 0x7a29555638e9 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2638:27
    #7 0x7a29555638e9 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (.constprop.0) /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2674:52
    #8 0x7a295554f16f in testing::Test::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2713:50
    #9 0x7a295554f16f in testing::Test::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2703:6
    #10 0x7a295554f36e in testing::TestInfo::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2859:14
    #11 0x7a295554f553 in testing::TestSuite::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:3037:33
    #12 0x7a295554f553 in testing::TestSuite::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2991:6
    #13 0x7a295555b708 in testing::internal::UnitTestImpl::RunAllTests() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:5967:47
    #14 0x7a295555bd78 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2638:27
    #15 0x7a295555bd78 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:2674:52
    #16 0x7a295555bd78 in testing::UnitTest::Run() /usr/src/debug/gtest/googletest-1.15.2/googletest/src/gtest.cc:5546:55
    #17 0x5ccdf721c5d0 in RUN_ALL_TESTS() /usr/include/gtest/gtest.h:2334:73
    #18 0x5ccdf721be50 in main src/test/TestMain.cpp:20:10
    #19 0x7a2954f45e07 in __libc_start_call_main /usr/src/debug/glibc/glibc/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #20 0x7a2954f45ecb in __libc_start_main /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:360:3
    #21 0x5ccdf70e4464 in _start (/home/mark/Coding/Repos/inputstream.adaptive/build_clang_debug_sanitizer/src/test/inputstream.adaptive_test+0xf30464) (BuildId: 53a3fced4234a38f5911a78d952158d8708ef61b)

SUMMARY: AddressSanitizer: heap-buffer-overflow src/test/TestHelper.h:84:35 in AESDecrypter::~AESDecrypter()
Shadow bytes around the buggy address:
  0x502000021000: fa fa fd fd fa fa fd fa fa fa fd fa fa fa fd fd
  0x502000021080: fa fa fd fa fa fa fd fd fa fa fd fa fa fa fd fd
  0x502000021100: fa fa fd fd fa fa fd fa fa fa fd fa fa fa fd fa
  0x502000021180: fa fa fd fa fa fa fd fd fa fa fd fd fa fa fd fa
  0x502000021200: fa fa fd fa fa fa fd fd fa fa fd fa fa fa fd fd
=>0x502000021280: fa fa fd fa fa fa 00[fa]fa fa 00 fa fa fa fd fa
  0x502000021300: fa fa 00 00 fa fa fd fa fa fa 00 00 fa fa 00 fa
  0x502000021380: fa fa fd fd fa fa fd fa fa fa fa fa fa fa fa fa
  0x502000021400: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x502000021480: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x502000021500: fa fa fa fa fa fa fa fa fa fa 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
==208457==ABORTING

This could be resolved more elegant with maybe a factory function but I'm too lazy right now.

Motivation and context

The tests shouldn't crash.

How has this been tested?

Tests run without crash.

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • I have read the Contributing document
  • My code follows the Code Guidelines of this project
  • My change requires a change to the Wiki documentation
  • I have updated the documentation accordingly

@neo1973 neo1973 added Type: Fix non-breaking change which fixes an issue v22 Piers labels Jan 2, 2025
Comment on lines 12 to 14
#ifndef INPUTSTREAM_TEST_BUILD
#include <kodi/Filesystem.h>
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree your change but please comment the code

Suggested change
#ifndef INPUTSTREAM_TEST_BUILD
#include <kodi/Filesystem.h>
#endif
// #ifndef INPUTSTREAM_TEST_BUILD
// #include <kodi/Filesystem.h>
// #endif

this is part of RenewLicense method that has been temporary comment out for a future full removal
has been kept only to see if some user complain about this old undocumented feature removal

AESDecrypter(const std::string& licenseKey) : m_licenseKey(licenseKey){};
virtual ~AESDecrypter() = default;
AESDecrypterTest(const std::string& licenseKey) : m_licenseKey(licenseKey) {};
virtual ~AESDecrypterTest() = default;

void decrypt(const AP4_UI08* aes_key,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the line 96 (i cant comment below)
please comment the method
// bool RenewLicense(const std::string& pluginUrl);
an oversight of what was explained on the my previous comment

@neo1973 neo1973 force-pushed the fix_ODR_violation branch from 73096e9 to a2861ee Compare January 3, 2025 16:23
Copy link
Collaborator

@CastagnaIT CastagnaIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@CastagnaIT CastagnaIT merged commit 8ddc249 into xbmc:Piers Jan 4, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Fix non-breaking change which fixes an issue v22 Piers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants