FDH2 / UxPlay

AirPlay Unix mirroring server
GNU General Public License v3.0
1.35k stars 72 forks source link

Crash shortly after iphone went into sleep #74

Closed rvoell-gcx closed 2 years ago

rvoell-gcx commented 2 years ago

After a short while when the iphone went to sleep and turned off its display, uxplay crashes with

*** buffer overflow detected ***: terminated
Aborted (core dumped)

I am using uxplay on a recent Arch linux and it has been build using AUR. It has been build from commit fbea7bdd764dcd882eb2d1784c4bd45816e91718. Iphone is a iPhone 6s Plus running iOS 15.3.1. uxplay has been started using uxplay -d, logfile can be found here: uxplay.log This does also happen when uxplay is used with the -nc option.

fduncanh commented 2 years ago

There is nothing shown as wrong in the debug trace.

can you build directly from github, and try again. There are instructions for arch in the README If you reproduce it again, I'll try with an iphone. can one trigger sleep with some action, or just have to wait?

rvoell-gcx commented 2 years ago

My understanding is that AUR/yay/mkpkg do build this directly from github but also create a package for the package manager. The PKGBUILD file in AUR enables the ZOOMFIX, so that would be only difference. Yes, you can wait or press the power button once.

fduncanh commented 2 years ago

Its clearer for me if you build directly from github. Its easy, and I dont need to investigate the AUR package

rvoell-gcx commented 2 years ago

No problem, i'll do that

rvoell-gcx commented 2 years ago

I tried it with and without release configuration, with and without the ZOOMFIX and with and without -nc parameter and their combinations. It did not crash. I tried also to strip the binary. I build a not stripped version using makepkg to get a backtrace:

raop_rtp_mirror tcp socket closed
*** buffer overflow detected ***: terminated

Thread 11 "uxplay" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffdcff9640 (LWP 77172)]
0x00007ffff73b034c in __pthread_kill_implementation () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff73b034c in __pthread_kill_implementation () at /usr/lib/libc.so.6
#1  0x00007ffff73634b8 in raise () at /usr/lib/libc.so.6
#2  0x00007ffff734d534 in abort () at /usr/lib/libc.so.6
#3  0x00007ffff73a4397 in __libc_message () at /usr/lib/libc.so.6
#4  0x00007ffff74432fa in __fortify_fail () at /usr/lib/libc.so.6
#5  0x00007ffff7441c16 in  () at /usr/lib/libc.so.6
#6  0x00007ffff744323b in  () at /usr/lib/libc.so.6
#7  0x0000555555564df5 in raop_rtp_mirror_thread (arg=<optimized out>) at /home/rvoell/build/uxplay-git/src/UxPlay/lib/raop_rtp_mirror.c:223
#8  0x00007ffff73ae5c2 in start_thread () at /usr/lib/libc.so.6
#9  0x00007ffff7433584 in clone () at /usr/lib/libc.so.6
fduncanh commented 2 years ago

you said It did not crash

are you saying the github bulld works, but AUR doesnt?

rvoell-gcx commented 2 years ago

Yes

fduncanh commented 2 years ago

maybe the issue in the AUR package is same as #69

rvoell-gcx commented 2 years ago

I don't think so, since the github build also has -march=native enabled. And i run it on the same machine as i build it on. But it must be some compiler option

fduncanh commented 2 years ago

So its an AUR packaging issue? and not uxplay?

fduncanh commented 2 years ago

post the AUR PKGBUILD script and I'll look at it

rvoell-gcx commented 2 years ago

Depends on what this causes. I don't think software should break if you change the optimization levels or something similar. Thank you for you help so far :smiley_cat:

fduncanh commented 2 years ago

so post the PKGBUILD!

rvoell-gcx commented 2 years ago

Here it is:

# Maintainer: Nico <d3sox at protonmail dot com>
pkgname=uxplay-git
_gitname=UxPlay
pkgver=r233.8ebac4c
pkgrel=2
pkgdesc="AirPlay Unix mirroring server"
arch=('any')
url="https://github.com/FDH2/$_gitname"
license=('GPL3')
depends=('gstreamer' 'gst-plugins-base' 'gst-plugins-base-libs' 'gst-libav' 'gstreamer-vaapi' 'avahi' 'libplist')
makedepends=('cmake' 'git')
conflicts=('uxplay')
provides=('uxplay')
source=("git+$url.git" "uxplay.desktop")
sha256sums=('SKIP' '6b43385942508d8c360e8360be52719cbf3899868f3560b245731d866fb245a3')

pkgver() {
  cd "$srcdir/$_gitname"

  # Get the version number.
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
  cd "$srcdir/$_gitname"
  mkdir -p build
  cd build
  cmake .. -DZOOMFIX=1
  cmake --build . --config Release
}

package() {
  # install binary
  install -Dm 755 "$srcdir/$_gitname/build/uxplay" "$pkgdir/usr/bin/uxplay"
  # install desktop file
  install -Dm 644 "$srcdir/uxplay.desktop" "$pkgdir/usr/share/applications/uxplay.desktop"

  printf "%b" "\e[1;33m==> WARNING: \e[0mIn order for UxPlay to work, the avahi systemd service has to be running. Enable it with: systemctl enable --now avahi-daemon\n"
  # install manpage
  install -Dm 644 "$srcdir/$_gitname/uxplay.1" "$pkgdir/usr/share/man/man1/uxplay.1"
  # install doc
  install -d "$pkgdir/usr/share/doc/uxplay"
  install -Dm 644 "$srcdir/$_gitname"/README.* "$pkgdir/usr/share/doc/uxplay"
  # install license
  install -Dm 644 "$srcdir/$_gitname/LICENSE" "$pkgdir/usr/share/licenses/uxplay/LICENSE"
}

Its from uxplay-git from the AUR

fduncanh commented 2 years ago

For packagers,

cmake .. -DZOOMFIX=1 should now be cmake -DZOOMFIX=1 -DNO_MARCH_NATIVE=1

see if this makes a difference. (I assume -DX=ON and -DX=1 are equivalent)

rvoell-gcx commented 2 years ago

I'll test it on Monday(i do not own an iphone). But i do not think it will make a difference. -march=native was also enabled for the manual build.

rvoell-gcx commented 2 years ago

My /etc/makepkg.conf adds -D_FORTIFY_SOURCE=2 to CFLAGS(i did not set this, so i assume this is standard in arch linux). But i do not understand where in line 223 in raop_rtp_mirror.c this should lead to a problem.

fduncanh commented 2 years ago

where do you get line 223 in raop_rtp_mirror.c from? This is initializing a new video connection

rvoell-gcx commented 2 years ago

From the backtrace i posted earlier: #7 0x0000555555564df5 in raop_rtp_mirror_thread (arg=<optimized out>) at /home/rvoell/build/uxplay-git/src/UxPlay/lib/raop_rtp_mirror.c:223

fduncanh commented 2 years ago

To identify the line of code, Is the source the current gitlab source, or something that might be older? last commit for this file was Feb 21.

rvoell-gcx commented 2 years ago

commit hash is 2584a55c3dcc73c84b8975062598d071159a5dc6

fduncanh commented 2 years ago

OK thats current

fduncanh commented 2 years ago

I saw your reported behavior crash on AUR but not on straight compile on my virtualbox arch. dont yet understand it.

fduncanh commented 2 years ago

To fix this I will have to modify the AUR download of the source after running makepkg -si and resinstall with changes, to print out things, and continue this change + recompile cycle till I identify the problem,

I have to use AUR compilation because a simple compile doesnt show the problem

but makepkg doesnt allow changes to the source to be made. how do I override this behavior (you are the AUR expert, not me)

EDIT make makepkg --noextract is the answer

makepkg -sief

fduncanh commented 2 years ago

OK I have found how to work on this with makepkg -sief

fduncanh commented 2 years ago

@rvoell-gcx FIXED. Thanks for bringing this to my attention. Please test to confirm.

It was a historic bug in the code which was masked by a race condition (so it only showed up in the AUR compilation, presumably because of modified build flags)

I had to examine the code history of the ancestral codes to see where it came from, and learned more about the code base......

rvoell-gcx commented 2 years ago

@fduncanh i tried it and didn't experience the crash again. Thank you very much for responding and fixing this fast. :smile: