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

Fix timer callback type #1173

Merged
merged 1 commit into from
Dec 2, 2021
Merged

Conversation

parasyte
Copy link
Contributor

@parasyte parasyte commented Dec 1, 2021

- Closes Rust-SDL2#1166
- `TimerCallback` has type: `Box<dyn FnMut() -> u32 + 'a + Send>`
@parasyte parasyte force-pushed the fix-timer-callback-type branch from a62ffd5 to 7b97dfd Compare December 1, 2021 15:34
@Cobrand
Copy link
Member

Cobrand commented Dec 1, 2021

Good catch!

@parasyte
Copy link
Contributor Author

parasyte commented Dec 2, 2021

FWIW, here's the full error output from ASAN:

=================================================================
==16377==ERROR: AddressSanitizer: global-buffer-overflow on address 0x559218ee3908 at pc 0x559217f1a82e bp 0x7fb5075e6ce0 sp 0x7fb5075e6cd8
READ of size 8 at 0x559218ee3908 thread T36 (SDLTimer)
    #0 0x559217f1a82d in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..Fn$LT$Args$GT$$GT$::call::hc8e055ad4633d733 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1708:9
    #1 0x559217f6ebf2 in sdl2::timer::c_timer_callback::h4ca1e963d949b157 /home/jay/other-projects/rust-sdl2/src/sdl2/timer.rs:92:14
    #2 0x559218365200 in SDL_TimerThread (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x6d5200)
    #3 0x559218364409 in SDL_RunThread (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x6d4409)
    #4 0x55921843042c in RunThread (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x7a042c)
    #5 0x7fb50b884608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477:8
    #6 0x7fb50b656292 in clone /build/glibc-eX1tMB/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95

0x559218ee3908 is located 56 bytes to the left of global variable 'alloc6904' defined in '25pit4d79pq9k2tn' (0x559218ee3940) of size 24
0x559218ee3908 is located 0 bytes to the right of global variable 'vtable.0' defined in '25pit4d79pq9k2tn' (0x559218ee38e0) of size 40
SUMMARY: AddressSanitizer: global-buffer-overflow /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1708:9 in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..Fn$LT$Args$GT$$GT$::call::hc8e055ad4633d733
Shadow bytes around the buggy address:
  0x0ab2c31d46d0: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9
  0x0ab2c31d46e0: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9
  0x0ab2c31d46f0: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9
  0x0ab2c31d4700: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9
  0x0ab2c31d4710: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 00 00 00
=>0x0ab2c31d4720: 00[f9]f9 f9 f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9
  0x0ab2c31d4730: 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9
  0x0ab2c31d4740: 00 00 00 f9 f9 f9 f9 f9 00 00 00 00 00 f9 f9 f9
  0x0ab2c31d4750: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9
  0x0ab2c31d4760: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9
  0x0ab2c31d4770: f9 f9 f9 f9 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9
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
Thread T36 (SDLTimer) created by T35 (timer::test::te) here:
    #0 0x559217e873bc in pthread_create /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:207:3
    #1 0x559218430539 in SDL_SYS_CreateThread (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x7a0539)
    #2 0x559218364c4c in SDL_CreateThreadInternal (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x6d4c4c)
    #3 0x5592183656d3 in SDL_TimerInit (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x6d56d3)
    #4 0x559218436774 in SDL_InitSubSystem_REAL (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x7a6774)
    #5 0x559217ef0aab in sdl2::sdl::TimerSubsystem::new::hc6b046a65ce3dfb0 /home/jay/other-projects/rust-sdl2/src/sdl2/sdl.rs:190:39
    #6 0x559217eefdc5 in sdl2::sdl::Sdl::timer::ha3a581cbe72e9e0a /home/jay/other-projects/rust-sdl2/src/sdl2/sdl.rs:133:9
    #7 0x559217eec665 in sdl2::timer::test::test_timer::h16be1738c2dcc439 /home/jay/other-projects/rust-sdl2/src/sdl2/timer.rs:103:9
    #8 0x5592180a811a in core::ops::function::FnOnce::call_once::hc9386cdf8b536607 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
    #9 0x55921800d42d in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h973d5648d79c7e16 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9
    #10 0x559218230092 in std::panicking::try::do_call::hec899806c2dbe85c /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40
    #11 0x5592182530ba in __rust_try (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x5c30ba)
    #12 0x559217f9e5e0 in std::panic::catch_unwind::h044b6dc66c782416 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14
    #13 0x559218186ebc in test::run_test_in_process::h28bad90e7bb33138 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:608:18
    #14 0x559218185663 in test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::hafbde9c221fda579 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:500:39
    #15 0x559218185d9f in test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h61922f71aa6c6cbc /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:527:37
    #16 0x55921800d564 in std::sys_common::backtrace::__rust_begin_short_backtrace::h3693b21315fc7d1c /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:123:18
    #17 0x5592180a385a in std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hb09c12af85b190d9 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:484:17
    #18 0x559217f9e93e in std::panic::catch_unwind::hfc7d75a09a385394 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14
    #19 0x5592180a471e in core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::hc6fecefacb41bb36 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
    #20 0x55921897c956 in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h87111aae3e89ce0b /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1694:9
    #21 0x55921869d5ef in std::sys::unix::thread::Thread::new::thread_start::h0345246c780f621d /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/thread.rs:108:17
    #22 0x7fb50b884608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477:8

Thread T35 (timer::test::te) created by T0 here:
    #0 0x559217e873bc in pthread_create /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:207:3
    #1 0x55921869c84e in std::sys::unix::thread::Thread::new::hf00f584d50d954cc /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/thread.rs:87:19
    #2 0x5592180a22dc in std::thread::Builder::spawn_unchecked::hc0304595d11e7df0 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:508:22
    #3 0x5592180a3966 in std::thread::Builder::spawn::hab62a41b1439bce7 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:389:18
    #4 0x5592181842fa in test::run_test::run_test_inner::hd8d6e9c1aba6266a /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:527:19
    #5 0x559218182c81 in test::run_test::h156b5d324a57f495 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:572:28
    #6 0x55921817614c in test::run_tests::hed06665dc7e12817 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:329:35
    #7 0x55921811c0b6 in test::console::run_tests_console::h57bad88b588eb7cf /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/console.rs:290:5
    #8 0x55921816f7f7 in test::test_main::h288860dffb9acd62 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:124:15
    #9 0x5592181706b0 in test::test_main_static::h44b94e3b6586d137 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:143:5
    #10 0x559217f80182 in sdl2::main::hc9138a528a958ae1 /home/jay/other-projects/rust-sdl2/src/sdl2/lib.rs:1:1
    #11 0x559217ee5d43 in std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h3b4198e651bace47 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:145:18
    #12 0x559218926c6e in std::panicking::try::do_call::h5e6ed75ca2a5a0c4 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40
    #13 0x55921892e27a in __rust_try (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0xc9e27a)
    #14 0x55921897e179 in std::panic::catch_unwind::hbd0a493d5e0aeb5e /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14
    #15 0x559218a282eb in std::rt::lang_start_internal::_$u7b$$u7b$closure$u7d$$u7d$::heee0b0e5c30a7d61 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:128:48
    #16 0x559218926e7d in std::panicking::try::do_call::hb3305b2b9c6bc34a /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40
    #17 0x55921892e27a in __rust_try (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0xc9e27a)
    #18 0x55921897dfd9 in std::panic::catch_unwind::h74a4efc6528f2263 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:133:14
    #19 0x559218a27b49 in std::rt::lang_start_internal::hc4524168e523b4c2 /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:128:20
    #20 0x559217ee5ca5 in std::rt::lang_start::h7ee1ab548d898ddd /home/jay/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:144:17
    #21 0x559217f801ab in main (/home/jay/other-projects/rust-sdl2/target/x86_64-unknown-linux-gnu/debug/deps/sdl2-a63e55622515db67+0x2f01ab)

==16377==ABORTING

@Cobrand Cobrand merged commit 5b2399d into Rust-SDL2:master Dec 2, 2021
@parasyte parasyte deleted the fix-timer-callback-type branch December 6, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

timer::test::test_timer test segfaults in rust 1.56.1
2 participants