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

Segmentation fault on mediainfo #5124

Closed
valpogus opened this issue Apr 4, 2020 · 18 comments · Fixed by #8161
Closed

Segmentation fault on mediainfo #5124

valpogus opened this issue Apr 4, 2020 · 18 comments · Fixed by #8161
Labels
bug report Something is not working properly

Comments

@valpogus
Copy link
Contributor

valpogus commented Apr 4, 2020

I just contributed an update to the packages libzen, libmediainfo and mediainfo. Unfortunately, this update leads to a segmentation fault when running the"mediainfo" command:

[~]$ gdb mediainfo
GNU gdb (GDB) 9.1
[...]
Reading symbols from mediainfo...
(No debugging symbols found in mediainfo)
(gdb) run
Starting program: /data/data/com.termux/files/usr/bin/mediainfo
warning: Unable to determine the number of hardware watchpoints available.
warning: Unable to determine the number of hardware breakpoints available.

Program received signal SIGSEGV, Segmentation fault.
0x0000007fb7c42198 in mbsnrtowcs () from /system/lib64/libc.so

The error appears to be caused by the new libzen library, since downgrading to 0.4.37-1 while keeping libmediainfo 20.03-1 and mediainfo 20.03-1 works.

Can the package libzen be rolled back to version 0.4.37-1 until a fix for version 0.4.38 is found?

Thanks and sorry for not testing before opening the pull request.

@Grimler91
Copy link
Member

Grimler91 commented Apr 5, 2020

I am not able to reproduce the segfault on aarch64 android 10 or arm android 7, so what is your output of termux-info?

@valpogus
Copy link
Contributor Author

valpogus commented Apr 5, 2020

Well, I'm relieved that at least I didn't break everyone's system 😄

My termux-info output:

Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://termux.org/packages/ stable main
# science-repo (sources.list.d/science.list)
deb https://dl.bintray.com/grimler/science-packages-24 science stable
# game-repo (sources.list.d/game.list)
deb https://dl.bintray.com/grimler/game-packages-24 games stable
Updatable packages:
All packages up to date
Android version:
7.1.1
Kernel build information:
Linux localhost 3.18.31-perf+ #1 SMP PREEMPT Fri Aug 18 15:38:03 CST 2017 aarch64 Android
Device manufacturer:
OnePlus
Device model:
ONEPLUS A3003

At the moment I don't have any other physical device on which to test. I tested using the Android SDK Emulator (system-images;android-29;google_apis;x86_64) and I cannot reproduce the error there either.

I would be nice to know if other people with similar devices also get this error.

@valpogus
Copy link
Contributor Author

valpogus commented Apr 5, 2020

I tested again with the emulator image for Android 7.1 (system-images;android-25;google_apis;x86_64) and there I can reproduce the segmentation fault. Running in gdb shows however the error "stack corruption detected" instead of the SIGSEGV when running on the phone.

@Grimler91
Copy link
Member

Could you install these debug builds: libzen-dbg_0.4.38-1_aarch64.deb, mediainfo-dbg_20.03-1_aarch64.deb and give gdb another shot?

@valpogus
Copy link
Contributor Author

valpogus commented Apr 5, 2020

I get this output with the libzen-dbg, mediainfo-dbg provided:

[~]$ gdb -q mediainfo
Reading symbols from mediainfo...
(gdb) run
Starting program: /data/data/com.termux/files/usr/bin/mediainfo
warning: Unable to determine the number of hardware watchpoints available.
warning: Unable to determine the number of hardware breakpoints available.

Program received signal SIGSEGV, Segmentation fault.
0x0000007fb7dba198 in mbsnrtowcs ()
   from /system/lib64/libc.so

I'm not really an expert with gdb, I only know about "run" 😕. Is there any option/command that I should use for more verbosity?

@Grimler91
Copy link
Member

Try bt after run, short for backtrace

@valpogus
Copy link
Contributor Author

valpogus commented Apr 5, 2020

Thanks for the tip! The results of the backtrace:

[~]$ gdb -q mediainfo
Reading symbols from mediainfo...
(gdb) run
Starting program: /data/data/com.termux/files/usr/bin/mediainfo
warning: Unable to determine the number of hardware watchpoints available.
warning: Unable to determine the number of hardware breakpoints available.

Program received signal SIGSEGV, Segmentation fault.
0x0000007fb7d86198 in mbsnrtowcs ()
   from /system/lib64/libc.so
(gdb) backtrace
#0  0x0000007fb7d86198 in mbsnrtowcs ()
   from /system/lib64/libc.so
#1  0x0000007fb7e6a370 in ZenLib::Ztring::From_Local (
    this=0x7ffffff2f0, S=0x0)
    at ../../../Source/ZenLib/Ztring.cpp:596
#2  0x000000555555925c in main (argc=1,
    argv_ansi=0x7ffffff468)
    at ../../../Source/CLI/CLI_Main.cpp:118

The code around line 596 in Ztring.cpp:

592                size_t Size=mbsrtowcs(NULL, &S, 0, NULL);
593                if (Size!=0 && Size!=(size_t)-1)
594                {
595                    wchar_t* WideString=new wchar_t[Size+1];
596                    Size=mbsrtowcs(WideString, &S, Size, NULL);
597                    WideString[Size]=L'\0';
598                    assign (WideString);
599                    delete[] WideString; //WideString=NULL;
600                }

The function used in the code is mbsrtowcs and not mbsnrtowcs like showed in the error... Besides, the function mbsrtowcs is also used on line 592 and there is no error there...

Does this look more like a Termux/Android specific error or a bug in the ZenLib code?

@ghost
Copy link

ghost commented Apr 5, 2020

Have you tried

export LD_PRELOAD=$PREFIX/lib/libandroid-support.so

before executing mediainfo ?

@Grimler91
Copy link
Member

Grimler91 commented Apr 5, 2020

cvs apparently has a similar problem: #3300, so it is probably a good idea to link cvs against libandroid-support as well if it fixes the issue for mediainfo.

For future reference: coreutils and mlocate also has problems without libandroid-support.

@valpogus
Copy link
Contributor Author

valpogus commented Apr 5, 2020

Have you tried

export LD_PRELOAD=$PREFIX/lib/libandroid-support.so

before executing mediainfo ?

Using export LD_PRELOAD=$PREFIX/lib/libandroid-support.so before running does fix the segmentation fault.

@ghost ghost deleted a comment from masouddastvarz Apr 5, 2020
@valpogus
Copy link
Contributor Author

valpogus commented Apr 6, 2020

Thanks for the fix! Unfortunately, the segmentation fault persists even with libzen-0.4.38-2. The backtrace message is the same.

I have created a patch to explicitly link libandroid-glob in the configure file (like I did for libandroid-glob) and rebuilt libzen again, but the segmentation fault is still there.

diff -u -r old/Project/GNU/Library/configure.ac ./Project/GNU/Library/configure.ac
--- old/Project/GNU/Library/configure.ac	2020-04-06 18:42:56.404327200 +0200
+++ ./Project/GNU/Library/configure.ac	2020-04-06 18:43:58.809568200 +0200
@@ -158,10 +158,10 @@
 dnl Common
 dnl
 if test "$enable_shared" = "yes"; then
-    ZenLib_LIBS="-L$(pwd)/.libs -lzen -lstdc++ -landroid-glob $ZenLib_LIBS"
+    ZenLib_LIBS="-L$(pwd)/.libs -lzen -lstdc++ -landroid-glob -landroid-support $ZenLib_LIBS"
 fi
 if test "$enable_static" = "yes"; then
-    ZenLib_LIBS_Static="$(pwd)/.libs/libzen.a -lstdc++ -landroid-glob $ZenLib_LIBS_Static"
+    ZenLib_LIBS_Static="$(pwd)/.libs/libzen.a -lstdc++ -landroid-glob -landroid-support $ZenLib_LIBS_Static"
 fi
 
 dnl #########################################################################
@@ -266,7 +266,7 @@
 dnl -------------------------------------------------------------------------
 dnl External libs
 dnl
-LDFLAGS="$LDFLAGS -lstdc++ -landroid-glob"
+LDFLAGS="$LDFLAGS -lstdc++ -landroid-glob -landroid-support"
 
 dnl #########################################################################
 dnl ### Output
diff -u -r old/Project/GNU/Library/libzen.pc.in ./Project/GNU/Library/libzen.pc.in
--- old/Project/GNU/Library/libzen.pc.in	2020-04-06 18:42:56.404327200 +0200
+++ ./Project/GNU/Library/libzen.pc.in	2020-04-06 18:43:58.809568200 +0200
@@ -4,10 +4,10 @@
 includedir=@includedir@
 Unicode=@ZenLib_Unicode@
 WstringMissing=@ZenLib_wstring_missing@
-Libs_Static=@libdir@/libzen.a -landroid-glob
+Libs_Static=@libdir@/libzen.a -landroid-glob -landroid-support
 
 Name: libzen
 Version: @PACKAGE_VERSION@
 Description: ZenLib
-Libs: -L${libdir} -lzen -lstdc++ -landroid-glob
+Libs: -L${libdir} -lzen -lstdc++ -landroid-glob -landroid-support
 Cflags: -I${includedir} @ZenLib_CXXFLAGS@

@Grimler91
Copy link
Member

Hm, weird..

@Grimler91 Grimler91 reopened this Apr 7, 2020
@ghost
Copy link

ghost commented Apr 7, 2020

 if test "$enable_shared" = "yes"; then
-    ZenLib_LIBS="-L$(pwd)/.libs -lzen -lstdc++ -landroid-glob $ZenLib_LIBS"
+    ZenLib_LIBS="-L$(pwd)/.libs -lzen -lstdc++ -landroid-glob -landroid-support $ZenLib_LIBS"
 fi
 if test "$enable_static" = "yes"; then
-    ZenLib_LIBS_Static="$(pwd)/.libs/libzen.a -lstdc++ -landroid-glob $ZenLib_LIBS_Static"
+    ZenLib_LIBS_Static="$(pwd)/.libs/libzen.a -lstdc++ -landroid-glob -landroid-support $ZenLib_LIBS_Static"
 fi

- try to add -landroid-support after $ZenLib_LIBS and $ZenLib_LIBS_Static.

@valpogus
Copy link
Contributor Author

valpogus commented Apr 7, 2020

  • try to add -landroid-support after $ZenLib_LIBS and $ZenLib_LIBS_Static.

Using the tip I have built libzen again using the following patch, but the segmentation fault is still there.

diff -u -r old/Project/GNU/Library/configure.ac ./Project/GNU/Library/configure.ac
--- old/Project/GNU/Library/configure.ac	2020-04-07 18:11:56.959566200 +0200
+++ ./Project/GNU/Library/configure.ac	2020-04-07 18:13:28.430947200 +0200
@@ -158,10 +158,10 @@
 dnl Common
 dnl
 if test "$enable_shared" = "yes"; then
-    ZenLib_LIBS="-L$(pwd)/.libs -lzen -lstdc++ -landroid-glob $ZenLib_LIBS"
+    ZenLib_LIBS="-L$(pwd)/.libs -lzen -lstdc++ -landroid-glob $ZenLib_LIBS -landroid-support"
 fi
 if test "$enable_static" = "yes"; then
-    ZenLib_LIBS_Static="$(pwd)/.libs/libzen.a -lstdc++ -landroid-glob $ZenLib_LIBS_Static"
+    ZenLib_LIBS_Static="$(pwd)/.libs/libzen.a -lstdc++ -landroid-glob $ZenLib_LIBS_Static -landroid-support"
 fi
 
 dnl #########################################################################
@@ -266,7 +266,7 @@
 dnl -------------------------------------------------------------------------
 dnl External libs
 dnl
-LDFLAGS="$LDFLAGS -lstdc++ -landroid-glob"
+LDFLAGS="$LDFLAGS -lstdc++ -landroid-glob -landroid-support"
 
 dnl #########################################################################
 dnl ### Output
diff -u -r old/Project/GNU/Library/libzen.pc.in ./Project/GNU/Library/libzen.pc.in
--- old/Project/GNU/Library/libzen.pc.in	2020-04-07 18:11:56.961540600 +0200
+++ ./Project/GNU/Library/libzen.pc.in	2020-04-07 18:13:30.683075100 +0200
@@ -4,10 +4,10 @@
 includedir=@includedir@
 Unicode=@ZenLib_Unicode@
 WstringMissing=@ZenLib_wstring_missing@
-Libs_Static=@libdir@/libzen.a -landroid-glob
+Libs_Static=@libdir@/libzen.a -landroid-glob -landroid-support
 
 Name: libzen
 Version: @PACKAGE_VERSION@
 Description: ZenLib
-Libs: -L${libdir} -lzen -lstdc++ -landroid-glob
+Libs: -L${libdir} -lzen -lstdc++ -landroid-glob -landroid-support
 Cflags: -I${includedir} @ZenLib_CXXFLAGS@

@ghost ghost added the bug report Something is not working properly label May 6, 2020
@stale
Copy link

stale bot commented Nov 18, 2021

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix Issue won't be fixed label Nov 18, 2021
@xtkoba

This comment has been minimized.

@stale stale bot removed the wontfix Issue won't be fixed label Nov 30, 2021
@xtkoba
Copy link
Contributor

xtkoba commented Dec 6, 2021

It seems like just a matter of symbol search order by the dynamic linker. Will be worked around by adding libandroid-support.so as DT_NEEDED in the main executable.

FYI, I am now facing a similar issue with krb5 package (#3326).

@xtkoba
Copy link
Contributor

xtkoba commented Dec 6, 2021

Note that by default a shared library is not linked against an executable which does not have any reference to symbols defined by the library:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Something is not working properly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants