wolpi / prim-ftpd

FTP server app for android
Other
580 stars 78 forks source link

Writing to external storage using SAF leads to file corruption if the filename includes square brackets [] #337

Closed r3a1d3a1 closed 1 month ago

r3a1d3a1 commented 3 months ago

It doesn't happen when writing to internal storage using PlainOldFS. The client I'm using is ncftp. The server (code: 63) runs on an Nvidia Shield (OS 9.1). The external storage is formatted as exFat. The corruption is silent, hence no errors on client or server side. It's in the form of missing the first 100KBs of a file of 100MBs size. Removing the brackets from the filename solves the issue, but since the corruption happens silently, it's quite dangerous.

wolpi commented 3 months ago

What could the app do about it? Automatically renaming files? In all cases? Are there other characters that cause such an issue? Would escaping help?

People might whant to keep their brakcets in filenames in working cases ...

r3a1d3a1 commented 3 months ago

Silent corruption is the worst. At the very least, it can throw an error telling the user to rename their files appropriately. Ideally, see where in the code brackets are mishandled and skip them with a backslash for example.

wolpi commented 3 months ago

Silent corruption is the worst.

yes, that is surly true.

At the very least, it can throw an error telling the user to rename their files appropriately.

Hhmm, not sure if a specific error message would make it's way through to be displayed on client. The server could log such cases or show them as toast. But both can easily been overseen.

I'll check error message handling.

see where in the code brackets are mishandled

Are you sure the root cause is not in android itself?

and skip them with a backslash for example.

That would be escaping. The question here is: what kind of escaping would help? Backslash would be a common escaping mechanism. It's not clear if it would help here. And it is also unclear if other characters would be affected, too.

wolpi commented 3 months ago

Ok, error messages make it through to client. Therfore checking for known bad characters and failing has been added.

r3a1d3a1 commented 3 months ago

After more testing: * and ? also cause silent corruption, despite getting automatically changed to _. \ erases the whole name up to and including itself. Btw, is unicode supported?

wolpi commented 2 months ago
  • and ? also cause silent corruption,

good to know.

Btw, is unicode supported?

Depends on where you look at. As this app is written in java the code itself supprots unicode. But it is not clear to me how protocols (ftp and sftp) handle encodings (can be figured out, takes some time) and what SAF actually does.