Bug 82630 - Documents opened via poppler_document_new_from_stream() do not render correctly
Summary: Documents opened via poppler_document_new_from_stream() do not render correctly
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: glib frontend (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2014-08-14 18:32 UTC by Phillip Berndt
Modified: 2014-09-13 13:38 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Example program (1.21 KB, text/plain)
2014-08-14 18:32 UTC, Phillip Berndt
Details
Example PDF (154.10 KB, application/pdf)
2014-08-14 18:33 UTC, Phillip Berndt
Details
Flawed rendering (49.89 KB, image/png)
2014-08-14 18:35 UTC, Phillip Berndt
Details
Example program (1.21 KB, text/plain)
2014-08-14 18:39 UTC, Phillip Berndt
Details
Bugfix (760 bytes, patch)
2014-08-15 10:02 UTC, Phillip Berndt
Details | Splinter Review
Another patch (1.41 KB, patch)
2014-09-12 17:24 UTC, Carlos Garcia Campos
Details | Splinter Review

Description Phillip Berndt 2014-08-14 18:32:57 UTC
Created attachment 104631 [details]
Example program

Files loaded through the poppler_document_new_from_stream() call seem not to be loaded correctly. While I can access all pages from PDFs, rendering fails halfway through a page, and on stderr I see

Syntax Error (153504): Unexpected end of file in flate stream
Syntax Error: Unterminated string
Syntax Error: End of file inside array
Syntax Error: Leftover args in content stream

If I load the same file into a char array and use poppler_document_new_from_data(), the file renderes fine.

I'll attach an example program, example PDF file, and screenshots of expected and actual renderings. I've compiled the example using

cc test.c -o test $(pkg-config --libs --cflags gtk+-3.0 glib-2.0 cairo gio-2.0 poppler-glib)

and tested against a clean build of the latest poppler git (commit e62e18e).
Comment 1 Phillip Berndt 2014-08-14 18:33:43 UTC
Created attachment 104632 [details]
Example PDF
Comment 2 Phillip Berndt 2014-08-14 18:35:51 UTC
Created attachment 104633 [details]
Flawed rendering
Comment 3 Phillip Berndt 2014-08-14 18:37:35 UTC
I'll skip the screensout of the expected output - pdfJS displays it correctly, Evince also does.
Comment 4 Phillip Berndt 2014-08-14 18:39:22 UTC
Created attachment 104634 [details]
Example program

Uploaded the wrong version before; fixed the example.
Comment 5 Phillip Berndt 2014-08-15 09:54:47 UTC
I did some debugging and believe that the error lies in PopplerInputStream. I don't understand how you use sub streams and copies yet though, therefore I haven't been able to fix it.

What I've found: At the top of PopplerInputStream::fillBuf(), I added some lines to check if bufPos coincides with the output of g_seekable_tell. When loading fails, it does not.

Another thing is that this seems to be a race condition: When I add sufficiently much debug output or blur/refocus the window to enforce a redraw, the output is rendered correctly.
Comment 6 Phillip Berndt 2014-08-15 10:02:09 UTC
Created attachment 104667 [details] [review]
Bugfix
Comment 7 Phillip Berndt 2014-08-15 16:06:44 UTC
With the bugfix I've uploaded earlier, the bug is gone.
Comment 8 Carlos Garcia Campos 2014-09-12 17:20:08 UTC
Comment on attachment 104667 [details] [review]
Bugfix

Thanks for the patch and sorry the delay reviewing it. I'm not sure this is the right fix, I think the actual problem is that saved member is not initialized, and a call to close() is making an invalid seek. I've found some other issues while debugging this, so I'll fix all of them.
Comment 9 Carlos Garcia Campos 2014-09-12 17:24:44 UTC
Created attachment 106201 [details] [review]
Another patch

Could you confirm this patch fixes the problem for you?
Comment 10 Phillip Berndt 2014-09-13 10:27:38 UTC
For the latest git version (f74a596) your patch also resolves the problem for me, in my example program as well as in the application where I actually need the function.
Comment 11 Carlos Garcia Campos 2014-09-13 13:38:14 UTC
(In reply to comment #10)
> For the latest git version (f74a596) your patch also resolves the problem
> for me, in my example program as well as in the application where I actually
> need the function.

Thanks for testing it. I've pushed the patch to both master and poppler-0.26 branches.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.