wa2c / cifs-documents-provider

CIFS Documents Provider
MIT License
232 stars 25 forks source link

Return 0 bytes read at End of File instead of -1 for safe functions. #56

Closed RebelliousX closed 7 months ago

RebelliousX commented 7 months ago

This is for (JCIFS, JCIFSNG, or SMBJ)ProxyFileCallbackSafe. The none safe onRead() functions return 0 bytes read at EOF. But I noticed SMBJ and JCIFS-NG (safe onRead()) return -1 to indicate EOF.

This causes lots of problems. The app trying to read a file might not expect to see -1 (wrapped to 4GB if 32bit) to be read and complains that the file size is not expected and too big.

Without this fix, an exception would have been thrown, a very long exception with stack trace error log. CIFS Document Provider completely crashes, and then afterwards, the notification of "Opening file" shows up and there is no file opened. I had to force close CIFS Document Provider then.

I am not sure about JCIFS (SMBv1), since my TrueNAS server doesn't support SMBv1, I can't test it. But I assume it would be the same, since JAVA usually returns -1 for end of file. I tested SMBJ and JCIFS-NG, which both had the same issue.

The program I used for testing, AetherSX2 loading BIOS file either SCPH10000.bin or SCPH39001.bin would trigger the issue. Which only happens on Safe transfers enabled. Below are screenshots of the logcat before and after.

The solution might not be optimal, feel free to modify as you like.

RebelliousX commented 7 months ago

This is before the modification: Screenshot 2023-11-15 193956

And this is after the fix: after

RebelliousX commented 7 months ago

sorry, I messed up my git commands, closing this and recreating it.