summaryrefslogtreecommitdiff
path: root/ebook-tools/crash-fix.patch
blob: 2389d299cf2d7c3f6c57876062d138cf05e2f123 (plain)
    1 From 93ebf942a90f9c95797838f9adab94bc0378671c Mon Sep 17 00:00:00 2001
    2 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
    3 Date: Tue, 30 Apr 2019 16:36:09 +0200
    4 Subject: [PATCH] Avoid crash on toc.ncx navPoint without navLabel
    5 
    6 Althoug at least one navLabel is required per navPoint, there is no
    7 guarantee it actually exists.
    8 
    9 Avoid crashes due to invalid accesses of a null label in case the toc is
   10 broken, and spew a warning.
   11 
   12 Fixes #8 epub_tit_next crashes on navPoint without navLabel.
   13 ---
   14  ebook-tools/src/libepub/epub.c | 5 +++--
   15  ebook-tools/src/libepub/opf.c  | 4 ++++
   16  2 files changed, 7 insertions(+), 2 deletions(-)
   17 
   18 diff --git a/ebook-tools/src/libepub/epub.c b/ebook-tools/src/libepub/epub.c
   19 index d085503..a259d9d 100644
   20 --- a/ebook-tools/src/libepub/epub.c
   21 +++ b/ebook-tools/src/libepub/epub.c
   22 @@ -469,8 +469,9 @@ int epub_tit_next(struct titerator *tit) {
   23    case TITERATOR_NAVMAP:
   24    case TITERATOR_PAGES:
   25      ti = GetNodeData(curr);
   26 -    tit->cache.label = 
   27 -      (char *)_opf_label_get_by_doc_lang(tit->epub->opf, ti->label);
   28 +    if (ti->label)
   29 +      tit->cache.label =
   30 +        (char *)_opf_label_get_by_doc_lang(tit->epub->opf, ti->label);
   31  
   32      if (! tit->cache.label)
   33        tit->cache.label = (char *)ti->id;
   34 diff --git a/ebook-tools/src/libepub/opf.c b/ebook-tools/src/libepub/opf.c
   35 index 6851db2..09bce9e 100644
   36 --- a/ebook-tools/src/libepub/opf.c
   37 +++ b/ebook-tools/src/libepub/opf.c
   38 @@ -398,6 +398,10 @@ void _opf_parse_navmap(struct opf *opf, xmlTextReaderPtr reader) {
   39       
   40        } else if (xmlTextReaderNodeType(reader) == 15) {
   41          if (item) {
   42 +          if (! item->label) {
   43 +            _epub_print_debug(opf->epub, DEBUG_WARNING, 
   44 +                              "- missing navlabel for nav point element");
   45 +          }
   46            _epub_print_debug(opf->epub, DEBUG_INFO, 
   47                              "adding nav point item->%s %s (d:%d,p:%d)", 
   48                              item->id, item->src, item->depth, item->playOrder);
   49 -- 
   50 2.21.0

Generated by cgit