libaacs should block mounting/unmounting the disc
On macOS libaacs has to unmount the disc for exclusive access and then mount it again when done with it. Both the mounting and unmounting are non-blocking, which leads to issues especially when mounting the disc again in the end because the function returns before the disc is actually mounted and users of the library then will try to access a not yet mounted device without a way to easily figure out when it is mounted again.
More detailed explanation:
void device_close(MMCDEV **pp) it calls
iokit_mount(mmc);, this function calls a macOS DiskArbitration function to mount the drive with
iokit_mount_complete as callback. In this callback
mmc is accessed and
is_mounted set to
1, but nothing else is done. This seems problematic given that there is no wait for this callback to happen, which means that by the time the callback is executed,
mmc might have been freed already. (And of course means that code that runs after will try to access the drive even though it is not yet mounted.)
Additionally it seems that the way
is_mounted is set is racy, though probably not as big of a problem given how the code works.
An easy fix would be to block in
iokit_mount until the device is actually mounted.
The same issue exists in the unmount function but luckily it seems it is fast enough to not cause an issue.
Related to libbluray#3 (closed)