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

IOT instruction (core dumped). Assertion '__n < this->size()' failed. #1151

Closed
duguyipiao opened this issue Aug 24, 2024 · 19 comments
Closed

Comments

@duguyipiao
Copy link

duguyipiao commented Aug 24, 2024

With the latest development version, I cannot open the attached file, which can be opened normally with mupdf.
I get the following core dumped error under linux.

/usr/include/c++/14.2.1/bits/stl_vector.h:1130: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
[1]    41151 IOT instruction (core dumped)  sioyek Supplemental__Material.pdf
@ahrm
Copy link
Owner

ahrm commented Aug 26, 2024

Can't reproduce the issue on linux. Some more information might help, e.g. what is your exact build process? (e.g. do you use the system's mupdf or the mupdf included in this repo?)

@duguyipiao
Copy link
Author

I installed the sioyek-git package from aur, which I think uses the system mupdf.

P.S. I'm using Manjaro Linux, which has libmupdf 1.24.8-1.

@vp1981
Copy link

vp1981 commented Aug 27, 2024

Hello.
I'm experiencing the same issue here with a different PDF file. Here is the output of the gdb bt:

[Thread 0x7fffa30006c0 (LWP 270944) exited]
/usr/include/c++/14.2.1/bits/stl_vector.h:1130: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Thread 1 "sioyek" received signal SIGABRT, Aborted.
Downloading source file /usr/src/debug/glibc/glibc/nptl/pthread_kill.c
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44	      return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007ffff22a5463 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:78
#2  0x00007ffff224c120 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff22334c3 in __GI_abort () at abort.c:79
#4  0x00007ffff24d3bb0 in std::__glibcxx_assert_fail (file=file@entry=0x55555588f6f8 "/usr/include/c++/14.2.1/bits/stl_vector.h", line=line@entry=1130,
    function=function@entry=0x555555891d48 "std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]",
    condition=condition@entry=0x555555888859 "__n < this->size()") at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/assert_fail.cc:41
#5  0x00005555556014d0 in std::vector<int, std::allocator<int> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/14.2.1/bits/stl_vector.h:1128
#6  std::vector<int, std::allocator<int> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/14.2.1/bits/stl_vector.h:1128
#7  Document::count_chapter_pages_accum (this=<optimized out>, accum_page_counts=...) at pdf_viewer/document.cpp:660
#8  Document::convert_toc_tree (this=this@entry=0x5555572eebd0, root=<optimized out>, root@entry=0x55555733d0b0, output=std::vector of length 8, capacity 8 = {...}) at pdf_viewer/document.cpp:814
#9  0x000055555560203d in Document::create_toc_tree (this=0x5555572eebd0, toc=std::vector of length 8, capacity 8 = {...}) at pdf_viewer/document.cpp:798
#10 0x000055555561511e in Document::load_document_caches (this=0x5555572eebd0, invalid_flag=0x5555560b5150, force_now=<optimized out>) at pdf_viewer/document.cpp:2934
#11 0x000055555560da65 in Document::open (this=0x5555572eebd0, invalid_flag=0x5555560b5150, force_load_dimensions=false, password="", temp=false) at pdf_viewer/document.cpp:1014
#12 0x000055555584da43 in DocumentView::open_document(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, bool*, bool, std::optional<OpenedBookState>, bool) [clone .constprop.0] [clone .isra.0] (
    this=this@entry=0x555555f44490, invalid_flag=invalid_flag@entry=0x5555560b5150, load_prev_state=load_prev_state@entry=true, force_load_dimensions=force_load_dimensions@entry=false, prev_state=..., doc_path=...) at pdf_viewer/document_view.cpp:752
#13 0x00005555556d1586 in MainWidget::open_document (this=0x5555560b4b50, path=..., offset_x=std::optional [no contained value], offset_y=std::optional [no contained value], zoom_level=std::optional [no contained value]) at pdf_viewer/main_widget.cpp:1920
#14 0x00005555556cc806 in handle_args (arguments=..., origin=<optimized out>, origin@entry=0x0) at pdf_viewer/main.cpp:620
#15 0x00005555555d05f1 in main (argc=<optimized out>, args=<optimized out>) at pdf_viewer/main.cpp:874

I hope this helps.

P.S. I'm on Archlinux with self-compiled sioyek from git (https://git.sr.ht/~vp1981/pkgbuild/tree/master/item/sioyek/PKGBUILD).

@ahrm
Copy link
Owner

ahrm commented Aug 27, 2024

This is very weird. The crash seems to be caused in this line:

accum += raw_page_count[i];
. But it is literally impossible for the index to be out of range because we check for that in the for loop. Can you set a breakpoint on Document::count_chapter_pages_accum and see exactly what happens in that function?

@vp1981
Copy link

vp1981 commented Aug 28, 2024

It's something really weird.

I built sioyek locally from git (with and without CONFIG=+debug) and it worked fine! Then I rebuilt the Archlinux package, but it still crashes at the same point.

The package build host is almost the same as the one I tested the sioyek local build on, but it is only accessible via ssh.

Another oddity is that the sioyek from the package is smaller than the local build, even after running strip:

LANG=en_US.UTF-8 stat -c '%s -- %n' ./sioyek ; stat -c '%s -- %n' /usr/bin/sioyek ; stat -c '%s -- %n' ./sioyek-nonstrip
5334000 -- ./sioyek
4977320 -- /usr/bin/sioyek
6619144 -- ./sioyek-nonstrip

Also, when I compared ldd output of the sioyek from the package and the local build, I see a difference in the linked files, the package one doesn't have those libraries:

libQt63DCore.so.6
libQt63DInput.so.6
libQt6Concurrent.so.6
libQt6Svg.so.6

even though all necessary packages are present on the build host.

So in my case there seems to be something wrong with the build host, I'll make a clean build host to try again.

P.S. The LFLAGS are different, but I don't know if that could be the reason for the mislinking.

@vp1981
Copy link

vp1981 commented Aug 28, 2024

I found a workaround to build a working package, but I don't know the real reason for the sioyek crashing.

The Archlinux adds the -Wp,-D_GLIBCXX_ASSERTIONS to CXXFLAGS by default, and this option is the reason why sioyek crashes.

When I build locally with

CXXFLAGS      = -pipe -std=c++17 -march=x86-64 -mtune=generic -O2 -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wp,-D_GLIBCXX_ASSERTIONS -std=gnu++1z -Wall -Wextra -mno-direct-extern-access -D_REENTRANT $(DEFINES)

sioyek crashes. Remove this option and sioyek works fine.

@ahrm
Copy link
Owner

ahrm commented Aug 29, 2024

Unfortunately I can't reproduce the bug event with -Wp,-D_GLIBCXX_ASSERTIONS on ubuntu. I think it is either a compiler bug or some sort of stack corruption (possibly due to using different versions of mupdf, note that the current development version of sioyek is designed for mupdf 1.22 so using version 1.24 might have weird consequences. You can try and link with the version of mupdf included in the repo and see if the bug happens there, adding sioyek_app_image to qmake options will use the included mupdf)

@pmiam
Copy link

pmiam commented Sep 14, 2024

I encountered this same error with a pdf copy of CFR title 10 by the US NRC. The file is available as a zip archive from the official library at https://www.nrc.gov/reading-rm/doc-collections/cfr/index.html

I am also using the latest sioyek-git from the AUR and I am running the latest Archlinux.

I tried to build from source using build_linux.sh. Unfortunately, I am missing the "lcms2mt.h" header file for the mupdf build. At this point I'm out of my depth and cannot spare much time to learn more, but I wonder if this might have something to do with the size difference vp1981 reported.

@ahrm
Copy link
Owner

ahrm commented Sep 15, 2024

Does the issue happen with the preview release here: https://github.com/ahrm/sioyek/releases/tag/sioyek3-alpha0 (the current preview is incompatible with the previous sioyek local.db and shared.db files, so before running the preview move those files to a different location, otherwise they might be corrupted).

@tokisuno
Copy link

tokisuno commented Sep 16, 2024

https://aur.archlinux.org/packages/sioyek

downloading from this aur package results in the same error on my system. going to try sioyek-git now before building from source.

@tokisuno
Copy link

tried with sioyek-git and had the same issue.

@ahrm
Copy link
Owner

ahrm commented Sep 17, 2024

Did you try with the alpha release AppImage that I posted above?

@vp1981
Copy link

vp1981 commented Sep 17, 2024

@tokisuno,
I think @ahrm is probably right, the problem is either the tooling or the mupdf version. As I wrote, I found a workaround to build a working package for my Archlinux hosts, but I don't think the sioyek and sioyek-git packages from AUR have the appropriate changes, so they would definitely fail.

P.S. I don't have time to figure out the cause right now, but I suspect the issue might be related to the mupdf library (Archlinux provides version 1.24.9), because Document::count_chapter_pages_accum works with mupdf functions.

@tokisuno
Copy link

@vp1981 The appimage seems to be working fine on my Desktop, but I have to try it on my laptop which has the issue.

Is the MuPDF package in Arch ahead or behind what's packaged with sioyek?

@ahrm
Copy link
Owner

ahrm commented Sep 18, 2024

It was ahead, I have recently updated the mupdf in development branch to the same version though.

@jsr-p
Copy link

jsr-p commented Nov 18, 2024

I found a workaround to build a working package, but I don't know the real reason for the sioyek crashing.

The Archlinux adds the -Wp,-D_GLIBCXX_ASSERTIONS to CXXFLAGS by default, and this option is the reason why sioyek crashes.

When I build locally with

CXXFLAGS      = -pipe -std=c++17 -march=x86-64 -mtune=generic -O2 -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wp,-D_GLIBCXX_ASSERTIONS -std=gnu++1z -Wall -Wextra -mno-direct-extern-access -D_REENTRANT $(DEFINES)

sioyek crashes. Remove this option and sioyek works fine.

thanks!
this issue has been bothering me for some time; removing the default CXXFLAG (specified inside /etc/makepkg.conf by default) did the trick.
concretely, I changed the build function inside the PKGBUILD file to:

build() {
  cd sioyek
  export CXXFLAGS="${CXXFLAGS/-Wp,-D_GLIBCXX_ASSERTIONS/}"
  qmake6 "CONFIG+=linux_app_image" pdf_viewer_build_config.pro
  make
}

I couldn't get it to work by passing it through yay directly; maybe somebody else knows?

and of course also a big thanks for sioyek @ahrm; best pdf viewer on linux without a doubt!

edit: I use arch btw

@hrdl-github
Copy link
Contributor

Someone referenced this issue in the AUR/sioyek-git comment section. Compiling with -O0 and debugging points towards a different issue when opening cfr-title-10.pdf, namely

int chapter_page = accum_chapter_pages[loc.chapter];
where loc.chapter is -1. With -O2 there is some obvious stack smashing, e.g. the capacity of raw_page_count becomes unreasonably large.

@hrdl-github
Copy link
Contributor

diff --git a/pdf_viewer/document.cpp b/pdf_viewer/document.cpp
index a2c8239..2b804a8 100644
--- a/pdf_viewer/document.cpp
+++ b/pdf_viewer/document.cpp
@@ -825,7 +825,7 @@ void Document::convert_toc_tree(fz_outline* root, std::vector<TocNode*>& output)
         if (root->page.page == -1) {
             float xp, yp;
             fz_location loc = fz_resolve_link(context, doc, root->uri, &xp, &yp);
-            int chapter_page = accum_chapter_pages[loc.chapter];
+            int chapter_page = (loc.chapter >= 0 && loc.chapter < accum_chapter_pages.size()) ? accum_chapter_pages[loc.chapter] : 0;
             current_node->page = chapter_page + loc.page;
         }
         else {

seems to work fine.

hrdl-github added a commit to hrdl-github/sioyek that referenced this issue Dec 12, 2024
@duguyipiao
Copy link
Author

duguyipiao commented Dec 12, 2024

@hrdl-github Thanks for fixing!

BTW, if you are the maintainer of the aur package, I think you forgot to delete line 31.

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

No branches or pull requests

7 participants