You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Running epubcheck on an epub with a large opf file (13k+ lines) results in a StackOverflowError #1358
When running epubcheck on an epub with a large opf file (13k+ lines, 841k) it throws the following StackOverflowError. Unfortunately I can't share the epub since it isn't public content.
epubcheck-4.2.6$ java -jar epubcheck.jar foobar.epub
Validating using EPUB version 3.2 rules.
java.lang.StackOverflowError
at java.base/java.util.LinkedList.unlinkFirst(LinkedList.java:178)
at java.base/java.util.LinkedList.poll(LinkedList.java:679)
at com.adobe.epubcheck.opf.XRefChecker.checkReadingOrder(XRefChecker.java:538)
at com.adobe.epubcheck.opf.XRefChecker.checkReadingOrder(XRefChecker.java:599)
at com.adobe.epubcheck.opf.XRefChecker.checkReadingOrder(XRefChecker.java:599)
I've seen that the recommended fix is to increase xss, but is there a way to change epubcheck to not require as much stack size?
This particular opf file has 6000+ <itemref> elements in the <spine>, and if I'm reading correctly it looks like these are evaluated using a recursive algorithm.
Question: Would changing the above to use iteration instead of recursion potentially decrease the required stack size?
We are having a similar issue, which is blocking some content ingestion. Looking at the code, the iterative version seems to be about one line shorter - I don't understand why this is using recursion at all. Java is not good at tail recursion optimizations. @rdeltour is this something we can look at in 5.0? The fix seems reasonably straightforward, do you want a PR?
Activity
bduga commentedon Nov 14, 2022
We are having a similar issue, which is blocking some content ingestion. Looking at the code, the iterative version seems to be about one line shorter - I don't understand why this is using recursion at all. Java is not good at tail recursion optimizations. @rdeltour is this something we can look at in 5.0? The fix seems reasonably straightforward, do you want a PR?
[Edit]: Oh, the reporter is us :) Hi Matt!
bduga commentedon Nov 14, 2022
FWIW, I think the recursion can be replaced with
for (URLReference ref : references) {...}. I think that should work with a Queue.rdeltour commentedon Nov 15, 2022
hi @myork and @bduga. Thanks for the report!
It seems this is the issue raised in PR #1356 by @kalaspuffar.
I'll look into it for v5.0.0, but need to merge the ongoing work first, as this code has been refactored and merging it early will create conflicts.
Would you be able to send the EPUB privately? I can possibly sign an NDA if needed.
fix: remove recursion in reading order checks