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

Segmentation fault crash while opening book #11680

Closed
jonnyl2 opened this issue Apr 15, 2024 · 14 comments · Fixed by #11863
Closed

Segmentation fault crash while opening book #11680

jonnyl2 opened this issue Apr 15, 2024 · 14 comments · Fixed by #11863
Milestone

Comments

@jonnyl2
Copy link
Contributor

jonnyl2 commented Apr 15, 2024

  • KOReader version: v2024.03.1-63
  • Device: Kobo Aura H2O (Also Android)

Issue

Scrambled Title - Scrambled author.epub.txt

When trying to open this file (scrambled for this report), the book first appears to load normally, but at around the halfway point of the progress bar, KOReader abruptly crashes.

Verbose crash.log:
04/15/24-10:11:51 DEBUG close widget: table: 0x30565e80 
04/15/24-10:11:51 DEBUG setDirty via a func from widget nil 
04/15/24-10:11:51 DEBUG creating coroutine for showing reader 
04/15/24-10:11:51 INFO  opening file /mnt/onboard/.Books/Scrambled Title - Scrambled author.epub 
04/15/24-10:11:51 DEBUG CreDocument: using cre call cache 
04/15/24-10:11:51 INFO  Inhibiting user input 
04/15/24-10:11:51 DEBUG ImageWidget: _render'ing resources/icons/mdlight/book.opened.svg 45 45 
04/15/24-10:11:51 DEBUG ImageWidget: initial offsets 0 0 
04/15/24-10:11:51 DEBUG CreDocument: applied cr3.ini default settings. 
04/15/24-10:11:51 DEBUG CreDocument: set fallback font faces: Noto Sans CJK SC|Noto Naskh Arabic|Noto Sans Devanagari UI|Noto Sans Bengali UI|FreeSans|FreeSerif|Noto Serif|Noto Sans 
04/15/24-10:11:51 DEBUG CreDocument: set adjusted fallback font sizes true 
04/15/24-10:11:51 DEBUG CreDocument: set monospace font scaling 100 
04/15/24-10:11:51 DEBUG building font face menu table 
04/15/24-10:11:51 DEBUG RD loaded plugin SSH at plugins/SSH.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin archiveviewer at plugins/archiveviewer.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin autodim at plugins/autodim.koplugin 
04/15/24-10:11:51 DEBUG AutoSuspend: init 
04/15/24-10:11:51 DEBUG AutoSuspend: start suspend/shutdown timer at 9326.940542 
04/15/24-10:11:51 DEBUG AutoSuspend: scheduling next suspend check in 1800 
04/15/24-10:11:51 DEBUG AutoSuspend: scheduling next shutdown check in 259200 
04/15/24-10:11:51 DEBUG RD loaded plugin autosuspend at plugins/autosuspend.koplugin 
04/15/24-10:11:51 DEBUG AutoWarmth: scheduleMidnightUpdate 
04/15/24-10:11:51 DEBUG RD loaded plugin autowarmth at plugins/autowarmth.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin backgroundrunner at plugins/backgroundrunner.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin batterystat at plugins/batterystat.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin bookshortcuts at plugins/bookshortcuts.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin calibre at plugins/calibre.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin coverbrowser at plugins/coverbrowser.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin docsettingtweak at plugins/docsettingtweak.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin exporter at plugins/exporter.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin gestures at plugins/gestures.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin httpinspector at plugins/httpinspector.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin keepalive at plugins/keepalive.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin movetoarchive at plugins/movetoarchive.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin newsdownloader at plugins/newsdownloader.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin opds at plugins/opds.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin patch_management at plugins/patchmanagement.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin perceptionexpander at plugins/perceptionexpander.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin profiles at plugins/profiles.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin qrclipboard at plugins/qrclipboard.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin readtimer at plugins/readtimer.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin statistics at plugins/statistics.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin systemstat at plugins/systemstat.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin terminal at plugins/terminal.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin texteditor at plugins/texteditor.koplugin 
04/15/24-10:11:51 DEBUG RD loaded plugin vocabbuilder at plugins/vocabbuilder.koplugin 
04/15/24-10:11:51 DEBUG CreDocument: set view mode page 
04/15/24-10:11:51 DEBUG CreDocument: set status line property 1 
04/15/24-10:11:51 DEBUG made tweak css:
body, p, li { text-align: left !important; }
p + p { margin-top: .5em !important; }[END] 
04/15/24-10:11:51 DEBUG CreDocument: set style sheet: ./data/epub.css and appended content (83 bytes) 
04/15/24-10:11:51 DEBUG CreDocument: set embedded fonts 1 
04/15/24-10:11:51 DEBUG CreDocument: set embedded style sheet 1 
04/15/24-10:11:51 DEBUG CreDocument: set block rendering flags 0x3375131 
04/15/24-10:11:51 DEBUG CreDocument: set render dpi 300 
04/15/24-10:11:51 DEBUG CreDocument: set page margins 42 21 42 43 
04/15/24-10:11:51 DEBUG CreDocument: set txt preformatted 1 
04/15/24-10:11:51 DEBUG CreDocument: set smooth scaling false 
04/15/24-10:11:51 DEBUG CreDocument: set nightmode images true 
04/15/24-10:11:51 DEBUG CreDocument: set font face Adobe Caslon Pro 
04/15/24-10:11:51 DEBUG CreDocument: set header font Noto Sans 
04/15/24-10:11:51 DEBUG CreDocument: set font size 41 
04/15/24-10:11:51 DEBUG CreDocument: set font base weight 0 = 400 
04/15/24-10:11:51 DEBUG CreDocument: set font hinting mode 2 
04/15/24-10:11:51 DEBUG CreDocument: set font kerning mode 1 
04/15/24-10:11:51 DEBUG CreDocument: set space width scale 95 
04/15/24-10:11:51 DEBUG CreDocument: set space condensing 85 
04/15/24-10:11:51 DEBUG CreDocument: set word expansion 0 
04/15/24-10:11:51 DEBUG CreDocument: set cjk width scaling 100 
04/15/24-10:11:51 DEBUG CreDocument: set interline space 105 
04/15/24-10:11:51 DEBUG CreDocument: set gamma index 49 
04/15/24-10:11:51 DEBUG CreDocument: set font-family font faces: ||||||FreeSerif|| 
04/15/24-10:11:51 DEBUG CreDocument: set textlang embedded langs true 
04/15/24-10:11:51 DEBUG CreDocument: set textlang hyphenation enabled true 
04/15/24-10:11:51 DEBUG CreDocument: set hyphenation trust soft hyphens 0 
04/15/24-10:11:51 DEBUG CreDocument: set textlang hyphenation soft hyphens only false 
04/15/24-10:11:51 DEBUG CreDocument: set textlang hyphenation force algorithmic false 
04/15/24-10:11:51 DEBUG CreDocument: set hyphenation left hyphen min 0 
04/15/24-10:11:51 DEBUG CreDocument: set hyphenation right hyphen min 0 
04/15/24-10:11:51 DEBUG CreDocument: set floating punctuation 0 
04/15/24-10:11:51 DEBUG Typography lang: using fallback  en-US , might be overriden by doc language 
04/15/24-10:11:51 DEBUG CreDocument: set textlang main lang en-US 
04/15/24-10:11:51 DEBUG UserHyph: reset user hyphenation dict 
04/15/24-10:11:51 DEBUG CreDocument: requesting DOM version: 20240114 
04/15/24-10:11:51 DEBUG CreDocument: set visible page count 1 
04/15/24-10:11:51 DEBUG CreDocument: loading document... 
04/15/24-10:12:00 DEBUG CreDocument: loading done. 
04/15/24-10:12:00 DEBUG   loading took 8.254 seconds 
04/15/24-10:12:00 DEBUG Typography lang: current en-US is same as doc language 
04/15/24-10:12:00 DEBUG CreDocument: set textlang main lang en-US 
04/15/24-10:12:00 DEBUG UserHyph: reset user hyphenation dict 
04/15/24-10:12:00 DEBUG CreDocument: rendering document... 
Segmentation fault
!!!!
Uh oh, something went awry... (Crash n°1: 04/15/24 @ 10:12:01)
Running FW 4.35.20400 on Linux 2.6.35.3-850-gbc67621+ (#3032 PREEMPT Mon Jan 9 13:37:40 CST 2017)
Attempting to restart KOReader . . .
!!!!

Converting the file on Calibre from epub to epub and epub to mobi didn't help.

The document opens fine on several other Android e-reader software (including AlReader, CoolReader, Document Viewer, Reasily, ReadEra).

There was a presumably similar issue reported here: #1675.

Thank you for your help.

@poire-z
Copy link
Contributor

poire-z commented Apr 15, 2024

Can reproduce, will investigate.

segmentation faults (aka segfaults) is just some generic crash that happens because of coding errors/oversights, there were many reports, but all for different reasons, so none is "similar" to any other :)

Thread 1 "luajit" received signal SIGSEGV, Segmentation fault.
ldomNode::isImage (this=this@entry=0x555557665330)
    at crengine/src/lvtinydom.cpp:20080
20080       switch (getNodeId()) {

#0  ldomNode::isImage (this=this@entry=0x555557665330) at src/lvtinydom.cpp:20080
#1  0x00007fffe04a4858 in ldomNode::getObjectImageRefName (this=this@entry=0x555557665330, percentDecode=percentDecode@entry=true)
    at src/lvtinydom.cpp:20115
#2  0x00007fffe04b8fff in ldomNode::getObjectImageSource (this=this@entry=0x555557665330) at src/lvtinydom.cpp:20200
#3  0x00007fffe055165b in getStyledImageSize (enode=enode@entry=0x555557665330, img_width=@0x7fffff7ff2d4: 0, img_height=img_height@entry=@0x7fffff7ff340: 0,
    container_width=container_width@entry=-1, container_height=container_height@entry=-1, enforce_page_constraints=enforce_page_constraints@entry=false)
    at src/lvrend.cpp:2686
#4  0x00007fffe055773a in getRenderedWidths (node=node@entry=0x555557665330, maxWidth=@0x7fffff7ff550: 0, minWidth=@0x7fffff7ff570: 0, direction=direction@entry=0,
    ignoreMargin=ignoreMargin@entry=false, rendFlags=rendFlags@entry=2147483647, curMaxWidth=@0x7fffff7ff46c: 0, curWordWidth=@0x7fffff7ff468: 0, collapseNextSpace=@0x7fffff7ff467: true,
    lastSpaceWidth=@0x7fffff7ff460: 0, indent=0, nowrap=false, lang_cfg=0x555557f371a0, processNodeAsText=false, isStartNode=true)
    at src/lvrend.cpp:11522
#5  0x00007fffe055976b in getRenderedWidths (node=node@entry=0x555557665330, maxWidth=@0x7fffff7ff550: 0, minWidth=@0x7fffff7ff570: 0, direction=direction@entry=0,
    ignoreMargin=ignoreMargin@entry=false, rendFlags=rendFlags@entry=2147483647) at src/lvrend.cpp:11456
#6  0x00007fffe0557978 in getRenderedWidths (node=node@entry=0x555557665330, maxWidth=@0x7fffff7ff780: 0, minWidth=@0x7fffff7ff7a0: 0, direction=direction@entry=0,
    ignoreMargin=ignoreMargin@entry=false, rendFlags=rendFlags@entry=2147483647, curMaxWidth=@0x7fffff7ff69c: 0, curWordWidth=@0x7fffff7ff698: 0, collapseNextSpace=@0x7fffff7ff697: false,
    lastSpaceWidth=@0x7fffff7ff690: 0, indent=0, nowrap=false, lang_cfg=0x555557f371a0, processNodeAsText=false, isStartNode=true)
    at src/lvrend.cpp:11575
[...]
#18337 0x00007fffe055976b in getRenderedWidths (node=node@entry=0x555557665330, maxWidth=@0x7fffffce47f0: 0, minWidth=@0x7fffffce4810: 0, direction=direction@entry=0,
    ignoreMargin=ignoreMargin@entry=false, rendFlags=rendFlags@entry=2147483647) at src/lvrend.cpp:11456
#18338 0x00007fffe0557978 in getRenderedWidths (node=node@entry=0x555557665330, maxWidth=@0x7fffffce4a20: 0, minWidth=@0x7fffffce4a40: 0, direction=direction@entry=0,
    ignoreMargin=ignoreMargin@entry=false, rendFlags=rendFlags@entry=2147483647, curMaxWidth=@0x7fffffce493c: 0, curWordWidth=@0x7fffffce4938: 0, collapseNextSpace=@0x7fffffce4937: false,
    lastSpaceWidth=@0x7fffffce4930: 0, indent=0, nowrap=false, lang_cfg=0x555557f371a0, processNodeAsText=false, isStartNode=true)
    at src/lvrend.cpp:11575
#18339 0x00007fffe055976b in getRenderedWidths (node=node@entry=0x555557665330, maxWidth=@0x7fffffce4a20: 0, minWidth=@0x7fffffce4a40: 0, direction=direction@entry=0,
    ignoreMargin=ignoreMargin@entry=false, rendFlags=rendFlags@entry=2147483647) at src/lvrend.cpp:11456
#18340 0x00007fffe0557978 in getRenderedWidths (node=node@entry=0x555557665330, maxWidth=@0x7fffffce4c50: 0, minWidth=@0x7fffffce4c70: 0, direction=direction@entry=0,
    ignoreMargin=ignoreMargin@entry=false, rendFlags=rendFlags@entry=2147483647, curMaxWidth=@0x7fffffce4b6c: 0, curWordWidth=@0x7fffffce4b68: 0, collapseNextSpace=@0x7fffffce4b67: false,
    lastSpaceWidth=@0x7fffffce4b60: 0, indent=0, nowrap=false, lang_cfg=0x555557f371a0, processNodeAsText=false, isStartNode=true)
    at src/lvrend.cpp:11575

.... and that backtrace doesn't seem to end, looks like an infinite loop and a huge stack overflow.

@poire-z
Copy link
Contributor

poire-z commented Apr 15, 2024

And indeed there was a coding error:

--- a/crengine/src/lvrend.cpp
+++ b/crengine/src/lvrend.cpp
@@ -11557,26 +11557,28 @@ void getRenderedWidths(ldomNode * node, int &maxWidth, int &minWidth, int direct
             if ( is_img || node->isBoxingInlineBox() ) {
                 if (!nowrap) {
                     // Get done with previous word
                     if (curWordWidth > minWidth)
                         minWidth = curWordWidth;
                     curWordWidth = 0;
                 }
                 collapseNextSpace = false;
                 lastSpaceWidth = 0;
                 int _maxw = 0;
                 int _minw = 0;
-                if ( is_img && img_width > 0) {
-                    // Inline img with a fixed width
-                    _maxw = img_width;
-                    _minw = img_width;
+                if ( is_img ) {
+                    if ( img_width > 0) {
+                        // Inline img with a fixed width
+                        _maxw = img_width;
+                        _minw = img_width;
+                    }
                 }
                 else {
                     // Get the rendered width of the inlineBox
                     getRenderedWidths(node, _maxw, _minw, direction, false, rendFlags);
                 }

fixes the infinite loop and segfault.

But then, we get lots of when rendering and turning pages:

CRE WARNING: resizeImage(width<=0 or height<=0)
CRE WARNING: resizeImage(width<=0 or height<=0)

ie. at the beginning of the book, there are pages that even Calibre struggles to render correctly:
image
There's supposed to be images in there, 30x1 pixels for the one I looked at.
image

Haven't yet investigated why these images end up being detected as having 0-width.

How are these pages supposed to look when not scrambled, in other reading software? Do you see images / lines ?

@Frenzie
Copy link
Member

Frenzie commented Apr 15, 2024

There was a presumably similar issue reported here: #1675.

Unlikely . :-) Segmentation fault just means some memory is being accessed or written that isn't accessible. So similar in that extremely generic sense only.

@jonnyl2
Copy link
Contributor Author

jonnyl2 commented Apr 15, 2024

How are these pages supposed to look when not scrambled, in other reading software? Do you see images / lines ?

The book is not very nicely formatted (as you can probably tell); it appears to be some conversion from PDF. It renders somewhat differently on all readers. The best job does AlReader. The page you showed above does not have any images. This is how it looks like on some other reader software (the original file looks the same):

ReadEra:
Screenshot_20240415_132903_org readera (1)

Reasily:
Screenshot_20240415_133259_com gmail jxlab app reasily (1)

AlReader:
Screenshot_20240415_133404_com neverland alreader (1)

Here is an example of a page that does have an actual image on the original (AlReader):
Screenshot_20240415_134839_com neverland alreader (1)

@jonnyl2
Copy link
Contributor Author

jonnyl2 commented Apr 15, 2024

Unlikely . :-) Segmentation fault just means some memory is being accessed or written that isn't accessible. So similar in that extremely generic sense only.

Understood. I said "presumably" and just mentioned it in case it could help :-)

@poire-z
Copy link
Contributor

poire-z commented Apr 15, 2024

Ok, the image ends up being 0-width because it's explicitely requested by the publisher CSS:

image

If you manage to stick in (or fix the CSS in the epub to set this width to other than 0):
.calibre20 { width: auto !important; height: auto !important }

You'll get - and you can go on reading:
image

Non-blocking segfault then :) No urgency making a PR, I'll keep that for my next batch of fixes.

@poire-z
Copy link
Contributor

poire-z commented Apr 15, 2024

Tip to be able to load the book and add/edit the book style tweak:

  • toggle Embedded styles to off globally (bottom menu, rightmost item, long-press)
  • load the book (so, without embedded styles)
  • add the Book style tweak
  • toggle Embedded styles to on + long-press to globally re-enable it.

@jonnyl2
Copy link
Contributor Author

jonnyl2 commented Apr 15, 2024

Great, thank you! I already edited the stylesheet in the original epub and it loaded fine. 💯

@jonnyl2
Copy link
Contributor Author

jonnyl2 commented May 19, 2024

Just came across another segfault today that fixes itself when I disable embedded style defaults before opening the book.

I should mention that I was reading several pages of this book back in June 2023 without incident. So something must have broken in an update since.

Here is the stylesheet.css of the book (sorry for the crappy formatting). Let me know if you can see what might be the culprit or if you need a scrambled copy of the book. Thank you.

html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}
body{font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}select,input,button,textarea{font:99% arial,helvetica,clean,sans-serif;}table{font-size:inherit;font:100%;}pre,code,kbd,samp,tt{font-family:monospace;*font-size:108%;line-height:100%;}
h1{font-size:138.5%;}h2{font-size:123.1%;}h3{font-size:108%;}h1,h2,h3{margin:1em 0;}h1,h2,h3,h4,h5,h6,strong{font-weight:bold;}abbr,acronym{border-bottom:1px dotted #000;cursor:help;}em{font-style:italic;}blockquote,ul,ol,dl{margin:1em;}ol,ul,dl{margin-left:2em;}ol li{list-style:decimal outside;}ul li{list-style:disc outside;}dl dd{margin-left:1em;}th,td{border:1px solid #000;padding:.5em;}th{font-weight:bold;text-align:center;}caption{margin-bottom:.5em;text-align:center;}p,fieldset,table,pre{margin-bottom:1em;}input[type=text],input[type=password],textarea{width:12.25em;*width:11.9em;}


table, td, tr {
	border:					0px;
	margin:					0px;
	padding:				0px;
}

@poire-z
Copy link
Contributor

poire-z commented May 19, 2024

Can't see - the styles may be innofensive as long as they don't apply to any element :)
So, I need a reproducible test case: either some sample.html including <style> (if you have some intuition of what may be the cause) that trigger the crash, or the scramble EPUB.

@jonnyl2
Copy link
Contributor Author

jonnyl2 commented May 20, 2024

I have no clue what it could be. Here is the scramble:

test - test_scrambled.epub.txt

@poire-z
Copy link
Contributor

poire-z commented May 20, 2024

Well, it doesn't crash for me - because it was the same cause as your other book above - and the same fix avoids it (removing my fix makes it crash).
We'll see for such books in our log - without crahsing:

CRE WARNING: resizeImage(width<=0 or height<=0)
CRE WARNING: resizeImage(width<=0 or height<=0)
CRE WARNING: resizeImage(width<=0 or height<=0)
CRE WARNING: resizeImage(width<=0 or height<=0)

So, all good, no more work needed :)

@jonnyl2
Copy link
Contributor Author

jonnyl2 commented May 20, 2024

That's good news! Any idea why it didn't crash yet back in June?

@poire-z
Copy link
Contributor

poire-z commented May 20, 2024

Not sure. I haven't change much about this bit of code in 2023/2024, but may be the bigger koreader/crengine#555 shuffled things around and new codepaths were taken that weren't last year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants