readium / kotlin-toolkit

A toolkit for ebooks, audiobooks and comics written in Kotlin
https://readium.org/kotlin-toolkit
BSD 3-Clause "New" or "Revised" License
163 stars 72 forks source link

[Bug] Failure when streaming a ZIP from the shared storage #526

Closed mickael-menu closed 2 weeks ago

mickael-menu commented 1 month ago

Describe the bug

I noticed a non deterministic bug when streaming a ZIP package from the shared storage. Sometimes we can't read a resource which fails with:

ZipException: invalid code lengths set
                   java.util.zip.InflaterInputStream.read(InflaterInputStream.java:184)

How to reproduce?

  1. Import BellaOriginal3.epub.zip in the Test App using "Read from shared storage" instead of "Import to app storage".
  2. Open the book.
  3. Close it and then try to reopen it right away. Do so until you observe a blank page and the following in the logs:
16:12:22.518  E  </head> closing tag not found in resource with href: null
16:12:22.519  E  </head> closing tag not found in resource with href: null
16:12:22.588  D  app_time_stats: avg=236.79ms min=14.65ms max=1976.69ms count=9
16:12:22.600  E  UserError: Publication looks corrupted.
                 ReadError.Decoding: An error occurred while attempting to decode the content.
                 EOFException: 
                   org.readium.r2.shared.util.zip.compress.utils.IOUtils.readFully(IOUtils.java:239)
                   org.readium.r2.shared.util.zip.compress.archivers.zip.ZipFile.setDataOffset(ZipFile.java:1275)
16:12:22.608  E  UserError: Publication looks corrupted.
                 ReadError.Decoding: An error occurred while attempting to decode the content.
                 ZipException: invalid code lengths set
                   java.util.zip.InflaterInputStream.read(InflaterInputStream.java:184)
                   org.readium.r2.shared.util.zip.compress.archivers.zip.InflaterInputStreamWithStatistics.read(InflaterInputStreamWithStatistics.java:83)

https://github.com/readium/kotlin-toolkit/assets/58686775/52429ad0-202d-4abd-a7c7-319feb321b3e

Readium version

develop

Android API version

34

Additional context

No response