Description
Unfortunately, a recent fix I made to improve PDF performances introduced a regression in seemingly random cases, where the content of a decrypted file is shifted.
This issue was caught by a unit test, but I couldn't find a fix, and didn't notice any actual issue during live testing. Since then with further testing in production, we noticed the bug happening randomly. Therefore, I will revert the fix in an upcoming PR.
For more in-depth explanation, it looks like the version of Minizip we're using has an issue with unzseek64()
. When seeking from the start of the resource, it will count from the ZIP entry header, instead of the actual content. Any subsequent read()
might therefore read part of the ZIP header, and the end of the actual content is not reachable (shifted). I "fixed" this by attempting to read a few bytes before seeking a "fresh" entry, but this caused some random crashes.
Possible solutions:
- Upgrading Minizip. Not easy, because we're already at the last version of the Swift wrapper, but we might attempt using directly the official C++ lib.
- Switching to another lib. There are not many available for iOS. A big contender (that we're already using with
r2-lcp-swift
) is ZIPFoundation, but I didn't find any equivalent to theunzseek()
function after a quick search.