Bug 404526 - Okular fails with Bogus memory allocation size
Summary: Okular fails with Bogus memory allocation size
Status: RESOLVED WORKSFORME
Alias: None
Product: okular
Classification: Applications
Component: PDF backend (show other bugs)
Version: 1.6.2
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-18 15:51 UTC by Kwanza.Pili
Modified: 2020-02-24 14:05 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kwanza.Pili 2019-02-18 15:51:51 UTC
SUMMARY
Using okular to display any PDF file results in a message "Bogus memory allocation size". The application runs, but does not show the contents of the file. However it does recognise the different pages which it renders as blanks.

STEPS TO REPRODUCE
1. Run okular <filename>
2. 
3. 

OBSERVED RESULT
Blank pages throughout.

EXPECTED RESULT
Display contents of files. To be clear, the files are not corrupt. All other viewers (atril, epdfview, mupdf, evince, kpdf (yes from KDE3), etc.) are capable of displaying the same files correctly.

SOFTWARE/OS VERSIONS
Windows: 
MacOS: 
Linux/KDE Plasma: opensuse leap 15
(available in About System)
KDE Plasma Version: 5.15
KDE Frameworks Version: 5.55.0
Qt Version: 5.12.1

ADDITIONAL INFORMATION
Comment 1 Albert Astals Cid 2019-02-18 19:48:06 UTC
So you're using leap or self compiled?

Seems to me this is a PEBKAC if this happens for al the files, since well, it works fine.

Or is it only for one particular file?
Comment 2 Kwanza.Pili 2019-02-18 21:50:34 UTC
My base OS is opensuse leap 15 but my QT/KDE packages are self-compiled, albeit based on opensuse source RPMs. The issue wih okular affects any file that is in the PDF format. I should add, this was also the base in v18.12.0. The problem is unique to okular - any other viewer will render the PDF files correctly.

As an aside, I came across a similar bug report from 2009. I wonder why it should recur 10 years hence?
Comment 3 Christoph Feck 2019-02-18 21:53:18 UTC
If you compile yourself, do you also install it into /usr using the cmake variables?
Comment 4 Kwanza.Pili 2019-02-19 10:31:58 UTC
No, I don't use /usr. The reason I compile both QT5 and KDE packages is that I install them in a different partition. i.e. /opt/kde. I have done this for several years without a problem from okular. It broke in the last two updates.
Comment 5 Christoph Feck 2019-02-19 19:51:22 UTC
Please make sure Okular finds its kpart and generator plugins by setting the environment variables to also point to your installation. If unsure, use strace to check.
Comment 6 Christoph Feck 2019-02-19 19:52:53 UTC
Please also note that openSUSE developers offer repositories with compiled versions of Okular, but from stable, as well as from unstable branch, so I don't see the need to compile yourself.
Comment 7 Christoph Feck 2019-02-19 19:54:19 UTC
Unless further information is provided, let's assume it's an error on your end.
Comment 8 Kwanza.Pili 2019-02-21 15:25:04 UTC
As I mentioned previously, I compile the packages because I install them in a available (non-standard) partition. What environment variable does okular need, please? or could someone point me to the part of the code that hard-codes that path. I presume this has changed in versions 18.12.x given that prior versions worked fine with precisely the same installation root? Moreover, all I change is the prefix from /usr to /opt/kde in all KDE apps.
Comment 9 Kwanza.Pili 2019-02-21 15:42:46 UTC
Looking back at a similar bug 10 years ago, I am tempted to suggest that the problem is due to the incomparability of this version of okular with the newer versions of poppler. I suspect the problems began when I upgraded to poppler-0.72; I now have poppler-0.74. If poppler is the cause, then I suppose okular won't work on my system.
Comment 10 Christoph Feck 2019-02-21 17:52:23 UTC
Regarding environment variables, please see https://community.kde.org/Guidelines_and_HOWTOs/Build_from_source#Set_up_the_runtime_environment

Okular works with poppler 0.72 on my system (openSUSE Krypton).
Comment 11 Kwanza.Pili 2019-02-21 20:19:18 UTC
OK thanks.

Setting the environments variables does not sort things. In fact, most of them were already set correctly. This leaves me even more convinced that it is an issue of the interaction of okular with poppler-0.74. I get this idea from [Bug 211526] which is precisely what I observe. 

A few other tools also also depend on the same poppler library, and they show mixed results:
- Texstudio also fails to show a PDF file with the same error (but I am not sure that it was designed to access PDF files that it did not generate)
- Calligra has not problem at all
- Dfm also works fine

I will try to rebuild texstudio since it I installed from the opensuse repositories directly, thus it was built with a different version of poppler.
Comment 12 Kwanza.Pili 2019-02-22 21:23:21 UTC
Just to close issue, I can confirm that this bug affects some applications (not all) that depend on poppler-qt5. Those that use poppler-glib are not affected. Moreover, QT5 is not the source of the problem - given that xpdf works fine, yet is uses  QT5 but not poppler-qt5. Therefore, I concluded that some function in okular and texstudio calling libpoppler-qt5.so.1 does not allocate memory properly which then causes libpoppler-qt5.so.1 to fail with the "bogus memory" warning. Searching online, I came across this explanation for a similar issue with a different app using an old version of poppler.

<< "Bogus memory allocation size" is given by
gmallocn(), gmallocn3(), or greallocn(). It is not raised by the
memory exhaust, but by the checking of invalid argument (e.g. requested
memory size ... numMember x sizeOfMember > INT_MAX, etc). ... >>

Anyway, just my 2 cents worth of explanation.
Comment 13 Kwanza.Pili 2019-03-31 20:11:08 UTC
For anyone who might come have a similar problem, I finally figured out the solution. I was blindly applying opensuse's build procedures, using their standard flags ("-Wl,--as-needed -Wl,--no-undefined -Wl,-Bsymbolic-functions"). If I build using  plain options (e.g. ArchLinux procedures), then the issue goes away. The lesson is: "do not set the linker flags to anything exotic!"