Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when opening a book #489

Open
grighakobian opened this issue Sep 30, 2024 · 17 comments
Open

Crash when opening a book #489

grighakobian opened this issue Sep 30, 2024 · 17 comments
Labels
bug Something isn't working triage Triage needed by maintainers

Comments

@grighakobian
Copy link
Contributor

grighakobian commented Sep 30, 2024

Describe the bug

We recently released a new version that included bug fixes for iOS 18. However, after the update, we noticed a significant drop in crash-free users—over 10%. In an attempt to resolve the issue, we downgraded the Readium version to 2.6.0, which previously did not cause any crashes. Unfortunately, this did not resolve the problem. Finally, we tried building the project with Xcode 15.4 instead of Xcode 16.0, and the crash issue was eliminated.

How to reproduce?

  1. Open a book

Readium version

2.6.0 ... 2.7.3

OS version

Mainly iOS 17 and 18

Testing device

Any Device

Environment

macOS: 15.0
platform: x86_64
carthage: 0.40.0
Xcode 16.0
Build version 16A242d

Additional context

Crashed: com.apple.root.default-qos
0 libsystem_platform.dylib 0x2a54 platform_memmove + 52
1 libxml2.2.dylib 0x18638 + 216
2 libxml2.2.dylib 0x6a58 xmlParserInputBufferCreateMem + 92
3 libxml2.2.dylib 0x67d4 xmlCreateMemoryParserCtxt + 72
4 libxml2.2.dylib 0x6610 xmlReadMemory + 60
5 0x101c55c XMLDocument.__allocating_init(string:encoding:) + 130 (Document.swift:130)
6 0x1171cb4 FuziXMLDocument.init(string:namespaces:) + 14 (Fuzi.swift:14)
7 0x1161dc8 MediaTypeSnifferContext.contentAsXML.getter + 74 (MediaTypeSnifferContext.swift:74)
8 0x115d170 specialized static MediaType.sniffHTML(context:) + 115 (MediaTypeSniffer.swift:115)
9 0x115b028 implicit closure #1 in variable initialization expression of static MediaType.sniffers + 32
10 0x115c704 specialized static MediaType.of(content:mediaTypes:fileExtensions:sniffers:) + 804 (Archive.swift:804)
11 0x115ca88 specialized static MediaType.of(
:mediaTypes:fileExtensions:sniffers:) + 280 (MediaTypeSnifferContent.swift:280)
12 0x115a6e8 static MediaType.of(:mediaTypes:fileExtensions:sniffers:) + 28 (:28)
13 0x11c1a84 PublicationServer.resourceHandler(
:) + 341 (PublicationServer.swift:341)
14 0xd81ddc thunk for @escaping @callee_guaranteed (@guaranteed GCDWebServerRequest) -> (@owned GCDWebServerResponse?) + 48 (:48)
15 0x122b680 __82-[GCDWebServer(Handlers) addHandlerForMethod:pathRegex:requestClass:processBlock:]_block_invoke + 923 (GCDWebServer.m:923)
16 0x122f704 -[GCDWebServerConnection(Subclassing) processRequest:completion:] + 762 (GCDWebServerConnection.m:762)
17 0x122cb94 -[GCDWebServerConnection _startProcessingRequest] + 152 (GCDWebServerConnection.m:152)
18 0x122d960 __45-[GCDWebServerConnection _readRequestHeaders]_block_invoke + 346 (GCDWebServerConnection.m:346)
19 0x122e2c8 __64-[GCDWebServerConnection(Read) readHeaders:withCompletionBlock:]_block_invoke + 461 (GCDWebServerConnection.m:461)
20 0x122e044 __68-[GCDWebServerConnection(Read) readData:withLength:completionBlock:]_block_invoke + 432 (GCDWebServerConnection.m:432)
21 libdispatch.dylib 0x31234 + 60
22 libdispatch.dylib 0x213c + 32
23 libdispatch.dylib 0x3dd4 + 20
24 libdispatch.dylib 0x15a6c + 864
25 libdispatch.dylib 0x1609c + 156
26 libsystem_pthread.dylib 0x48f8 _pthread_wqthread + 228
27 libsystem_pthread.dylib 0x10cc start_wqthread + 8

@grighakobian grighakobian added bug Something isn't working triage Triage needed by maintainers labels Sep 30, 2024
@grighakobian grighakobian changed the title [Crash] Crash when opening a book [Bug] Crash when opening a book Sep 30, 2024
@grighakobian grighakobian changed the title [Bug] Crash when opening a book Crash when opening a book Sep 30, 2024
@grighakobian
Copy link
Contributor Author

grighakobian commented Sep 30, 2024

You can download the crash reports here.

@tnorbert
Copy link

tnorbert commented Oct 2, 2024

We are experiencing the same issue. When building with Xcode 16, some users experience the same crash. Unfortunately(?), the crash is not consistant, for some users it never crashes. I have yet to have any workaround.

@tnorbert
Copy link

tnorbert commented Oct 3, 2024

I have new information about this "bug" It seems that the application only crashes in Relaese mode, so when downloaded from TestFlight. Building through xcode doesn't cause the code to crash. Any idea? I tried several combos, I tried using xcode 15.4, xcode 16, I tried using my iPhone 15 Plus and another iPhone x and even an iPhone 7. Maybe the problem is around the optimization level or something? I would be glad to hear any tip.

@tnorbert
Copy link

tnorbert commented Oct 3, 2024

Okay, I found the issue. For my defense, I got this project from others and it is an old one :) It looks like the library was updated from 2.2.0 to 2.6.0 at some point without doing the 2.5.0 migratin guide. Although it worked at that time, it looks like now this is causing this crash. I changed the implementation to use the GCDHTTPServer.shared as shown in the guide and the crash seems to go away.

@mickael-menu
Copy link
Member

@grighakobian Was it the same issue as described by @tnorbert above for you?

@grighakobian
Copy link
Contributor Author

@mickael-menu We haven't migrated to 2.5.0 yet; we're currently using version 2.7.3. Everything works fine when building on Xcode 15.4, but we're encountering crashes when building on Xcode 16.

@mickael-menu
Copy link
Member

@grighakobian Could you share your code creating an instance of EPUBNavigatorViewController? (Just all the parameters you pass to the constructor).

@tnorbert
Copy link

tnorbert commented Oct 9, 2024

@grighakobian @mickael-menu So, basically, my steps were to update the library to 2.7.3 and resolve every deprecated message. This includes using a new initializer in EPUBNavigatorViewController (and switching to GCDHTTPServer.shared) and reimplementing the user preferences (saving the preferences by our own logic and applying these values directly to the reader). After these steps, all our crashed went away. Although, these changes made us rework some of our epubs as the new reader did not apply several user preferences such as font sizes. It turned out that some epubs needed to be changed.

@grighakobian
Copy link
Contributor Author

@grighakobian Could you share your code creating an instance of EPUBNavigatorViewController? (Just all the parameters you pass to the constructor).

@mickael-menu Here is the EPUBNavigatorViewController initialization code.

let navigatorViewController = EPUBNavigatorViewController(publication: publication, initialLocation: initialLocation, resourcesServer: publicationServer)

Note that we are using the old PublicationServer API.

@mickael-menu
Copy link
Member

Okay that's probably why this is crashing on Xcode 16. Let me know if you still have the issue after migrating the HTTP server.

@tnorbert
Copy link

@mickael-menu Unfortunately, I started getting these crashes, too. At first, I though I solved this but it looks like I was wrong. Right now, I am getting the exact same crashes as @grighakobian. Any idea on that? The user's download it from TestFlight and when the device is fully offline (airplane mode and wifi off), the app crashes when trying to open an epub.

@mickael-menu
Copy link
Member

No but it's actually crashing in one of our third-party dependencies. Maybe you can take a look on Fuzi's repository to see if something similar was mentioned, and/or open an issue there: https://github.com/cezheng/Fuzi

Please let me know if you do so I can track the answers.

@mickael-menu
Copy link
Member

The project looks pretty dead actually. Maybe it's time to look for another XML parser.

If someone wants to contribute a solution with an alternative XML parser, you need to implement the following protocol: https://github.com/readium/swift-toolkit/blob/develop/Sources/Shared/Toolkit/XML/XML.swift

Here's an example using Fuzi: https://github.com/readium/swift-toolkit/blob/develop/Sources/Shared/Toolkit/XML/Fuzi.swift

And there are tests here, you just need to copy and adjust the FuziTests class:

class FuziTests: XCTestCase {
lazy var tester = XMLTester { xml, namespaces in
try FuziXMLDocument(string: xml, namespaces: namespaces)
}
func testParseInvalidXML() { tester.testParseValidXML() }
func testParseValidXML() { tester.testParseValidXML() }
func testParseHTML5() { tester.testParseHTML5() }
func testDocumentElement() throws { try tester.testDocumentElement() }
func testFirstElement() throws { try tester.testFirstElement() }
func testAllElements() throws { try tester.testAllElements() }
func testLocalName() throws { try tester.testLocalName() }
func testAttribute() throws { try tester.testAttribute() }
}

@mickael-menu mickael-menu reopened this Oct 21, 2024
@tnorbert
Copy link

tnorbert commented Oct 21, 2024

@mickael-menu It looks like somebody opened a new issue here and it is the same fuzi crash as we are experiencing.

#495

I think this is going to be a bigger issue now, I don't think that there is an easy solution but I am going to try to solve it somehow, without switching the parser (we kinda need it to be fixed asap as we are using this in production :) )

@mickael-menu
Copy link
Member

What's your plan to fix it? I guess we can't without fixing the issue in Fuzi. Forking it in Readium is a possibility if you find the solution by modifying Fuzy directly.

@tnorbert
Copy link

@mickael-menu I wrote a temporary solution in the other ticket but it is only a band aid for production crashes. @grighakobian What was your situation? Did you manage to solve this?

@readium readium deleted a comment Oct 24, 2024
@grighakobian
Copy link
Contributor Author

@tnorbert We fixed the crash by compiling the project on Xcode 15.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Triage needed by maintainers
Projects
None yet
Development

No branches or pull requests

3 participants