You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The root cause of this issue actually seems to be with the SRT v1.5.1 library itself, which is the version srtdroid currently uses. The issue appears to be fixed in the upcoming SRT v1.5.2, but I thought I'd flag this and share a workaround in case anyone else is having this issue now.
Summary: When not connected to the internet, calling connect(ip, addr) on a Socket and using a hostname for ip results in a SIGSEGV (SEGV_MAPERR), causing the app to suffer a fatal crash that cannot be caught.
Steps to reproduce:
Build and use the example srtdroid app (or a StreamPack example).
Disconnect from the internet (e.g. with airplane mode)
Set the IP to a hostname that needs name resolution (e.g. "stream.example.com")
Attempt to start streaming as a client.
Expected Result: A catchable exception indicating a problem with resolving the hostname and connecting.
Actual Result: A segfault that causes the app to crash.
Crash Log:
13:51:47.158 A Cmdline: io.github.thibaultbee.srtdroid.examples
13:51:47.158 A pid: 8576, tid: 9021, name: pool-2-thread-1 >>> io.github.thibaultbee.srtdroid.examples <<<
13:51:47.158 A #00 pc 00000000000d4ef0 /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/lib/arm64/libsrt.so (srt::sockaddr_any::set(sockaddr const*)+28) (BuildId: fdc6a370d36f35a297172064143a3ffda8af6552)
13:51:47.158 A #01 pc 00000000000c12d8 /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/lib/arm64/libsrt.so (srt::sockaddr_any::sockaddr_any(sockaddr const*, int)+48) (BuildId: fdc6a370d36f35a297172064143a3ffda8af6552)
13:51:47.158 A #02 pc 00000000000c1714 /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/lib/arm64/libsrt.so (srt::CUDTUnited::connect(int, sockaddr const*, int, int)+64) (BuildId: fdc6a370d36f35a297172064143a3ffda8af6552)
13:51:47.158 A #03 pc 00000000000c9e2c /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/lib/arm64/libsrt.so (srt::CUDT::connect(int, sockaddr const*, int, int)+76) (BuildId: fdc6a370d36f35a297172064143a3ffda8af6552)
13:51:47.158 A #04 pc 00000000001b764c /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/lib/arm64/libsrt.so (srt_connect+40) (BuildId: fdc6a370d36f35a297172064143a3ffda8af6552)
13:51:47.159 A #05 pc 0000000000048cbc /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/lib/arm64/libsrtdroid.so (nativeConnect(_JNIEnv*, _jobject*, _jobject*)+268) (BuildId: 93b3944d1b7a9566336affa7f58ce4cf754645ed)
13:51:47.159 A #08 pc 00000000000042d6 [anon:dalvik-classes3.dex extracted in memory from /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/base.apk!classes3.dex] (io.github.thibaultbee.srtdroid.models.Socket.connect+10)
13:51:47.159 A #10 pc 0000000000004288 [anon:dalvik-classes3.dex extracted in memory from /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/base.apk!classes3.dex] (io.github.thibaultbee.srtdroid.models.Socket.connect+20)
13:51:47.159 A #12 pc 000000000000131e [anon:dalvik-classes8.dex extracted in memory from /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/base.apk!classes8.dex] (io.github.thibaultbee.srtdroid.examples.tests.TestClient.launchImpl+70)
13:51:47.159 A #14 pc 00000000000016e6 [anon:dalvik-classes8.dex extracted in memory from /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/base.apk!classes8.dex] (io.github.thibaultbee.srtdroid.examples.tests.Test.launch$lambda-0+46)
13:51:47.159 A #16 pc 0000000000001630 [anon:dalvik-classes8.dex extracted in memory from /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/base.apk!classes8.dex] (io.github.thibaultbee.srtdroid.examples.tests.Test.$r8$lambda$jc03Nn7oJUZ8jpk4I2t67O96Xqs+0)
13:51:47.159 A #18 pc 00000000000011e4 [anon:dalvik-classes8.dex extracted in memory from /data/app/~~h1598JzzdNyrg5M-YH0GfQ==/io.github.thibaultbee.srtdroid.examples-AlyMPdm6iVgGO74-GGbuFg==/base.apk!classes8.dex] (io.github.thibaultbee.srtdroid.examples.tests.Test$$ExternalSyntheticLambda0.run+12)
Analysis:
Socket.connect(ip, addr) is an alias for Socket.connect(InetSocketAddress(ip, addr)). InetSocketAddress provides name resolution if ip is a hostname and not an IP address. However, if name resolution fails, its getAddress() method returns null. Since InetSocketAddress::getNative(...) returns nullptr when getAddress() is null (InetSocketAddress.h:55), the sockaddr pointer passed into srt_connect(...) at glue.cpp:300 is a null pointer.
In the SRT library, srt_connect wraps CUDT::connect which calls CUDTUnited::connect. In v1.5.1, there is no null check for the sockaddr*, and it gets dereferenced when constructing sockaddr_any in the method at netinet_any.h:148, resulting in the segfault. In v1.5.2, they've added a null check at api.cpp:1244 which appears to fix the issue.
Workarounds:
A. Compile srtdroid by changing the SRT version to 1.5.2-rc2 or similar in CMakeLists.txt. This seems to fix the crash in the srtdroid example app (showing a connection error popup instead). I haven't tested if any features are affected by the new version though.
B. Do val foo = InetSocketAddress(ip, port) yourself, check if foo.address is null, and call Socket.connect(foo) directly with this safe InetSocketAddress so no null pointer is passed into the underlying library. This is the solution I've used in the extension to StreamPack I'm working on so I didn't have to recompile srtdroid.
The text was updated successfully, but these errors were encountered:
geosir
changed the title
Segfault when attempting to connect using hostname without internet
Segfault when attempting to connect using hostname without internet (SRT v1.5.1)
Jun 8, 2023
I agree that it makes sense to wait for the stable 1.5.2 release. I just figured it might be useful to submit a report in case anyone was searching for the same issue.
The root cause of this issue actually seems to be with the SRT v1.5.1 library itself, which is the version srtdroid currently uses. The issue appears to be fixed in the upcoming SRT v1.5.2, but I thought I'd flag this and share a workaround in case anyone else is having this issue now.
Summary: When not connected to the internet, calling
connect(ip, addr)
on a Socket and using a hostname forip
results in a SIGSEGV (SEGV_MAPERR), causing the app to suffer a fatal crash that cannot be caught.Steps to reproduce:
Expected Result: A catchable exception indicating a problem with resolving the hostname and connecting.
Actual Result: A segfault that causes the app to crash.
Crash Log:
Analysis:
Socket.connect(ip, addr)
is an alias forSocket.connect(InetSocketAddress(ip, addr))
. InetSocketAddress provides name resolution ifip
is a hostname and not an IP address. However, if name resolution fails, itsgetAddress()
method returns null. SinceInetSocketAddress::getNative(...)
returns nullptr whengetAddress()
is null (InetSocketAddress.h:55), the sockaddr pointer passed intosrt_connect(...)
at glue.cpp:300 is a null pointer.In the SRT library,
srt_connect
wrapsCUDT::connect
which callsCUDTUnited::connect
. In v1.5.1, there is no null check for the sockaddr*, and it gets dereferenced when constructingsockaddr_any
in the method at netinet_any.h:148, resulting in the segfault. In v1.5.2, they've added a null check at api.cpp:1244 which appears to fix the issue.Workarounds:
A. Compile srtdroid by changing the SRT version to
1.5.2-rc2
or similar in CMakeLists.txt. This seems to fix the crash in the srtdroid example app (showing a connection error popup instead). I haven't tested if any features are affected by the new version though.B. Do
val foo = InetSocketAddress(ip, port)
yourself, check iffoo.address
is null, and callSocket.connect(foo)
directly with this safe InetSocketAddress so no null pointer is passed into the underlying library. This is the solution I've used in the extension to StreamPack I'm working on so I didn't have to recompile srtdroid.The text was updated successfully, but these errors were encountered: