Segmentation error in FTcpListener on Android without INTERNET permission

When packaging the project for Android, I used the UPL mechanism to remove unnecessary permissions, including network access permission:

<androidManifestUpdates>
	<removePermission android:name="android.permission.INTERNET" />
	<removePermission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<removePermission android:name="android.permission.ACCESS_WIFI_STATE" />
</androidManifestUpdates>

The application, which runs fine with that permission, now crashes.

It seems the problem is with FTcpListener, which experiences a segmentation error (please see log).

I did not use FTcpListener in my code, I don’t know why it is being executed.

Info: built for API level 19, OpenGL ES2, ATC. Problem observed both when launching from editor and when installing packaged .apk.

D/UE4     (15555): LogSockets:Warning: Failed to create socket Stream [FTcpListener server]
F/libc    (15555): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 15645 (FTcpListener)
I/DEBUG   (20265): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (20265): Build fingerprint: 'samsung/hltexx/hlte:5.0/LRX21V/N9005XXUGBOK6:/release-keys'
I/DEBUG   (20265): Revision: '8'
I/DEBUG   (20265): ABI: 'arm'
I/DEBUG   (20265): pid: 15555, tid: 15645, name: FTcpListener  >>> net..unreality <<<
I/DEBUG   (20265): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
I/DEBUG   (20265):     r0 00000000  r1 00000000  r2 913e1c48  r3 00003d1d
I/DEBUG   (20265):     r4 93fd28a0  r5 9575bfc0  r6 936fc010  r7 00000000
I/DEBUG   (20265):     r8 936fc060  r9 936fc0b0  sl 936fc100  fp 913e1d50
I/DEBUG   (20265):     ip a0f5a15c  sp 913e1c40  lr b6f253f7  pc 9f1d2e10  cpsr 40070010
I/DEBUG   (20265): 
I/DEBUG   (20265): backtrace:
I/DEBUG   (20265):     #00 pc 04d95e10  /data/app/net..unreality-1/lib/arm/libUE4.so (FTcpListener::Init()+760)
I/DEBUG   (20265):     #01 pc 01a4c94c  /data/app/net..unreality-1/lib/arm/libUE4.so (FRunnableThreadPThread::Run()+120)
I/DEBUG   (20265):     #02 pc 019c68a0  /data/app/net..unreality-1/lib/arm/libUE4.so (FRunnableThreadPThread::_ThreadProc(void*)+184)
I/DEBUG   (20265):     #03 pc 000137bb  /system/lib/libc.so (__pthread_start(void*)+30)
I/DEBUG   (20265):     #04 pc 0001189b  /system/lib/libc.so (__start_thread+6)

Edit: I looked at the possible source of the crash.

The log message Failed to create socket can be seen in [SocketSubsystemBSD.cpp][1] and is issued before returning a nullptr socket:

if (!NewSocket)
{
	UE_LOG(LogSockets, Warning, TEXT("Failed to create socket %s [%s]"), *SocketType.ToString(), *SocketDescription);
}

return NewSocket;

The crash is happening in [FTcpListener::Init][2]. As I understand it, the FTcpSockerBuilder returns nullptr and then the SetReceiveBufferSize is called on nullptr.
Probably checking Socket != nullptr again can fix that.

if (Socket == nullptr)
{
	Socket = FTcpSocketBuilder(TEXT("FTcpListener server"))
		.AsReusable()
		.BoundToEndpoint(Endpoint)
		.Listening(8);
	// <- the log message suggests this returns nullptr

	int32 NewSize = 0;
	Socket->SetReceiveBufferSize(2*1024*1024, NewSize); // <- crash here?
}

I would be grateful for your help.

https://.com/EpicGames/UnrealEngine/blob/4.14/Engine/Source/Runtime/Sockets/Private/BSDSockets/SocketSubsystemBSD.cpp#L48
[2]: https://.com/EpicGames/UnrealEngine/blob/4.14/Engine/Source/Runtime/Networking/Public/Common/TcpListener.h#L137

Hi ,

Wow, your app doesn’t require internet access at all. This seems like a tough permission to revoke. Net access is central to many inbuilt features in an app.

There are many settings in an unreal project that need internet access, can you check that the settings that are dependent on internet access has been disabled ? Also there are plugins that are dependent on internet settings.

As far as android is concerned, there are many default files that are copied into an unreal project that need internet access. Check out the pic of my folder which contains many default files.

Check out your intermediate folder and see if you find any files that need internet access.

Your error feels like there is still some feature or setting that is dependent on internet/network access.

Thanks

Thank you for your reply.

Even if those features do not work without internet access, the application should never crash with a segmentation error (illegal memory access).
The program should write to log something like "Connection failed, feature F will be disabled" but not crash.

My game is single-player so generally the its purpose is to display graphics. No network is needed for that.

Getting a SIGSEGV (most probably due to calling a method on null pointer) is never the correct behaviour, so it needs to be fixed anyway.

This is a situation that took the devs by surprise: usually if there is no internet you can create a socket but it will not connect to anything.
Here due to the removed permission the OS refused to create a socket, so it was left null.

,

Could you please upload your full monitor.bat log where this SIGSEGV Signal 11 error is occurring? Please upload it as a .txt file.

Thank you!

Thank you for looking at the issue.

Here is the [log file][1] recorded when the application crashed.

And a [minimal project][2] needed to replicate it.

http://.net/external/android_net_crash.txt
[2]: http://.net/external/AndroidNetCrash_project.7z

,

Removing network permissions on a build that’ll be launched will cause a crash on the Android device. If you’re simply packaging it however, it will not require networking connection permissions. If you are packaging using cook on the fly, that’ll be another reason why your project is crashing.

Thanks!

Thank you.

Is there some variable in MyProject.Build.cs or node in UPL through which my build script could distinguish whether it is launching locally or packaging the APK for deployment?