Skip to content

Running epubcheck on an epub with a large opf file (13k+ lines) results in a StackOverflowError #1358

Closed

Description

@myork

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?

Activity

  1. bduga commented on Nov 14, 2022

    @bduga

    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!

  2. bduga commented on Nov 14, 2022

    @bduga

    FWIW, I think the recursion can be replaced with for (URLReference ref : references) {...}. I think that should work with a Queue.

  3. rdeltour commented on Nov 15, 2022

    @rdeltour
    Member

    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.

    Unfortunately I can't share the epub since it isn't public content.

    Would you be able to send the EPUB privately? I can possibly sign an NDA if needed.

  4. self-assigned this
    on Nov 17, 2022
  5. added this to the v5.0.0-beta milestone on Nov 17, 2022
  6. added
    type: bugThe issue describes a bug
    status: in progressThe issue is being implemented by the development team
    and removed on Nov 17, 2022
  7. added a commit that references this issue on Nov 28, 2022
    6cbbefa
  8. added and removed
    status: in progressThe issue is being implemented by the development team
    on Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: completedWork completed, can be closedtype: bugThe issue describes a bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址