magnusja / libaums

Open source library to access USB Mass Storage devices on Android without rooting your device
Apache License 2.0
1.26k stars 270 forks source link

Prevent communication usage after closing #380

Closed depau closed 1 year ago

depau commented 1 year ago

This is more of a workaround for poor coding in EtchDroid but I think it would be helpful to everyone anyway.

Since I'm now uglily doing asynchronous I/O (sort of) it sometimes happens that I throw an exception while performing an operation, close the device in the finally block, but meanwhile the I/O thread finishes up a .read() on the block device while closed causing a use-after-free inside libusb.

This clearly isn't great user experience.

These changes ensure that the device isn't closed before any communication is performed, throwing an IllegalStateException if that's not the case. It still crashes but the user experience is better than SIGSEGV :)

magnusja commented 1 year ago

Thanks a lot!

WIll release a new version. Also there is GPT support now, although probably not very interesting for you :D

depau commented 1 year ago

I decided to ditch all features that aren't strictly "verbatim byte copy to block device" since as you may have noticed I haven't had lots of fun maintaining it over the last 3 years or so, so not really interesing for my use cases :)

It's good to hear though! I was reading you also support FAT16 now and that sounds cool considering I might get around to add support for the USB floppy protocol at some point. It'll be very fun to write Plop Boot Manager using an Android phone :)

magnusja commented 1 year ago

FAT16 is not really supported. Only with java-fs but yeah, that is a little experimental Id say :D

But if needed I think it can be implemented on top of FAT32 fairly easily. Another option would be https://github.com/waldheinz/fat32-lib