Cannot open files from SFTP with other apps
Description
I tried to open a PDF file located on a SFTP server with 3 different apps, none of them did work. If I copy the file to internal storage there is no issue opening it.
Setting
Device: Samsung Galaxy J3 (SM-J320F) OS: LineageOS 14.1 App version: 1.5.2 release
Log
08-31 21:22:49.876 1236 1628 I ActivityManager: START u0 {act=android.intent.action.VIEW dat=content://me.zhanghai.android.files.file_provider/sftp**************.pdf typ=application/pdf flg=0x3000003 cmp=com.artifex.mupdf.viewer.app/com.artifex.mupdf.viewer.DocumentActivity (has extras)} from uid 10070 on display 0
08-31 21:22:49.919 6657 6657 I MuPDF : OPEN URI content://me.zhanghai.android.files.file_provider/sftp**************.pdf
08-31 21:22:49.919 6657 6657 I MuPDF : MAGIC (Intent) application/pdf
08-31 21:22:49.930 6731 6744 E DatabaseUtils: Writing exception to parcel
08-31 21:22:49.930 6731 6744 E DatabaseUtils: android.os.NetworkOnMainThreadException
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at java.net.SocketOutputStream.write(SocketOutputStream.java:157)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at zb.j.r(:13)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at ub.d$a.a(:19)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at ub.d.flush(:3)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at xb.r.m(:3)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at xb.r.f(:7)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at xb.r.a()
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at xb.r.l(:2)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at oa.b.k(:9)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at na.b.e()
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at na.b.l()
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at na.c.v()
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at d.b.I0(:2)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at d.b.a1()
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at me.zhanghai.android.files.file.FileProvider.query(:2)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at android.content.ContentProvider.query(ContentProvider.java:1022)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at android.content.ContentProvider$Transport.query(ContentProvider.java:240)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
08-31 21:22:49.930 6731 6744 E DatabaseUtils: at android.os.Binder.execTransact(Binder.java:565)
08-31 21:22:49.932 6657 6657 I MuPDF : NAME null
08-31 21:22:49.932 6657 6657 I MuPDF : SIZE -1
08-31 21:22:49.932 6657 6657 I MuPDF : Opening document content://me.zhanghai.android.files.file_provider/sftp**************.pdf
08-31 21:22:49.939 6731 6766 E JavaBinder: *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
08-31 21:22:49.939 6731 6766 E JavaBinder: java.lang.ArrayIndexOutOfBoundsException: length=256; index=-5
08-31 21:22:49.939 6731 6766 E JavaBinder: at net.schmizz.sshj.common.Buffer.p()
08-31 21:22:49.939 6731 6766 E JavaBinder: at zb.d.d(:4)
08-31 21:22:49.939 6731 6766 E JavaBinder: at zb.j.r(:10)
08-31 21:22:49.939 6731 6766 E JavaBinder: at ub.d$a.a(:19)
08-31 21:22:49.939 6731 6766 E JavaBinder: at ub.d.flush(:3)
08-31 21:22:49.939 6731 6766 E JavaBinder: at xb.r.m(:3)
08-31 21:22:49.939 6731 6766 E JavaBinder: at xb.r.f(:7)
08-31 21:22:49.939 6731 6766 E JavaBinder: at xb.r.a()
08-31 21:22:49.939 6731 6766 E JavaBinder: at xb.p.e(:5)
08-31 21:22:49.939 6731 6766 E JavaBinder: at oa.b.d()
08-31 21:22:49.939 6731 6766 E JavaBinder: at oa.b.e()
08-31 21:22:49.939 6731 6766 E JavaBinder: at na.c.r(:20)
08-31 21:22:49.939 6731 6766 E JavaBinder: at me.zhanghai.android.files.file.FileProvider.openFile(:8)
08-31 21:22:49.939 6731 6766 E JavaBinder: at android.content.ContentProvider.openAssetFile(ContentProvider.java:1379)
08-31 21:22:49.939 6731 6766 E JavaBinder: at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1559)
08-31 21:22:49.939 6731 6766 E JavaBinder: at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1625)
08-31 21:22:49.939 6731 6766 E JavaBinder: at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:424)
08-31 21:22:49.939 6731 6766 E JavaBinder: at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313)
08-31 21:22:49.939 6731 6766 E JavaBinder: at android.os.Binder.execTransact(Binder.java:565)
08-31 21:22:50.120 1236 1257 I ActivityManager: Displayed com.artifex.mupdf.viewer.app/com.artifex.mupdf.viewer.DocumentActivity: +222ms
There are two exceptions in the stacktrace - one is NetworkOnMainThreadException during FileProvider.query() which I may work around on my side (although the calling app will be unresponsive for a short while - they really shouldn't do it on main thread). The other ArrayIndexOutOfBoundsException is in SSHJ and I can't fix. If it continues to happen after I fix the first exception, we'll need to file a bug to SSHJ.
@zhanghai Thank you for the quick response. I did more testing. The first exception seems to occur only when the MuPDF-library is involved. The other one occurs with all document viewers I tested so far.
Considering the results it would probably make sense to focus on the exception in SSHJ but that's just me guessing. If you can argue that it should be fixed in SSHJ I can file a bug. I am just missing the knowledge to back it up.
I forgot to mention: Sporadically I get this ArrayIndexOutOfBoundsException and the SFTP is completely inaccessible. Then I have to restart MaterialFiles such that it restarts a connection to the server.
What is the app version you are using? Is it from Play or F-Droid?
What is the app version you are using? Is it from Play or F-Droid?
F-Droid
I see. I would suggest you to file a bug with SSHJ, but unfortunately the F-Droid build was created by F-Droid server and they didn't provide the stacketrace deobfuscation file mapping.txt so your stacktrace won't be useful to SSHJ author to debug it. (For the Play version, which is also the version in GitHub releases, I did upload its mapping.txt along with the APK.)
I did retrace the stacktrace. I think it is a known issue: https://github.com/hierynomus/sshj/issues/532 The root cause could be the same as in #704.
I have the same issue. I was opening a 66 Byte text file

Using ES file explorer's text editor gives more infomation.

Edit: after restarting Material files the intergrated text editor works again. The other issue persists.
I started looking into this issue again. I managed to reproduce it in android studio. The first exception actually happens in fetching the file attributes: client.stat(path.remotePath) in Client.kt. I tried a stupid workaround and the file opened just fine:
return try {
// client.stat(path.remotePath)
val builder = FileAttributes.Builder()
builder.build()
} catch (e: IOException) {
throw ClientException(e)
}