After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 784963 - password-protected cbz file hangs evince
password-protected cbz file hangs evince
Status: RESOLVED FIXED
Product: evince
Classification: Core
Component: comics
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Evince Comics Maintainers
Evince Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-07-14 21:46 UTC by Hanno Böck
Modified: 2017-07-23 08:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
hang.cbz (358 bytes, application/vnd.comicbook+zip)
2017-07-14 21:46 UTC, Hanno Böck
  Details
password-and-real-images.cbz (1.70 KB, application/vnd.comicbook+zip)
2017-07-17 15:50 UTC, Hanno Böck
  Details
password-and-zero-size-files.cbz (358 bytes, application/vnd.comicbook+zip)
2017-07-17 15:50 UTC, Hanno Böck
  Details
comics: Add test program for archive handling code (4.59 KB, patch)
2017-07-18 14:30 UTC, Bastien Nocera
none Details | Review
comics: Add API to detect whether an archive entry is encrypted (2.10 KB, patch)
2017-07-18 14:30 UTC, Bastien Nocera
none Details | Review
comics: Add error reporting to comics_document_list() (2.86 KB, patch)
2017-07-18 14:30 UTC, Bastien Nocera
none Details | Review
comics: Return an error when archive contents are encrypted (2.17 KB, patch)
2017-07-18 14:30 UTC, Bastien Nocera
none Details | Review
comics: Use error returned by comics_document_list() (1.16 KB, patch)
2017-07-18 14:30 UTC, Bastien Nocera
reviewed Details | Review
comics: Throw an error if the mime-type cannot be read (1.14 KB, patch)
2017-07-18 14:31 UTC, Bastien Nocera
reviewed Details | Review
comics: Split off checking whether a file has a supported extension (1.99 KB, patch)
2017-07-18 14:53 UTC, Bastien Nocera
none Details | Review
comics: Check for supported extensions in initial list loop (4.24 KB, patch)
2017-07-18 14:53 UTC, Bastien Nocera
none Details | Review
comics: Return an error when archive contents are encrypted (2.33 KB, patch)
2017-07-18 15:42 UTC, Bastien Nocera
none Details | Review
shell: Fix typo in comment (869 bytes, patch)
2017-07-18 15:43 UTC, Bastien Nocera
none Details | Review
libdocument: Remove unused has_document_security() function (2.18 KB, patch)
2017-07-18 15:43 UTC, Bastien Nocera
none Details | Review
shell: Fix crash when comics says it's encrypted (1.00 KB, patch)
2017-07-18 15:43 UTC, Bastien Nocera
none Details | Review
comics: Add test program for archive handling code (4.59 KB, patch)
2017-07-22 13:02 UTC, Bastien Nocera
committed Details | Review
comics: Don't strip filenames in archive (1.14 KB, patch)
2017-07-22 13:02 UTC, Bastien Nocera
committed Details | Review
comics: Add API to detect whether an archive entry is encrypted (2.10 KB, patch)
2017-07-22 13:02 UTC, Bastien Nocera
committed Details | Review
comics: Add error reporting to comics_document_list() (3.12 KB, patch)
2017-07-22 13:02 UTC, Bastien Nocera
committed Details | Review
comics: Return an error when archive contents are encrypted (2.33 KB, patch)
2017-07-22 13:02 UTC, Bastien Nocera
committed Details | Review
comics: Propagate an error if the mime-type cannot be read (881 bytes, patch)
2017-07-22 13:02 UTC, Bastien Nocera
committed Details | Review
comics: Split off checking whether a file has a supported extension (1.97 KB, patch)
2017-07-22 13:02 UTC, Bastien Nocera
committed Details | Review
comics: Check for supported extensions in initial list loop (4.23 KB, patch)
2017-07-22 13:03 UTC, Bastien Nocera
committed Details | Review
shell: Fix typo in comment (869 bytes, patch)
2017-07-22 13:03 UTC, Bastien Nocera
committed Details | Review
shell: Fix crash when comics says it's encrypted (1.00 KB, patch)
2017-07-22 13:03 UTC, Bastien Nocera
committed Details | Review

Description Hanno Böck 2017-07-14 21:46:01 UTC
Created attachment 355662 [details]
hang.cbz

When creating a password protected zip archive and renaming it to .cbz then this will cause a hang in evince. The unzip process will even continue to run (and cause high load - I don't know why...) after exiting evince.

The reason is obvious: evince calls the unzip command line tool and doesn't expect any interaction from it.
Comment 1 André Klapper 2017-07-16 18:30:31 UTC
Thanks for reporting this. Which Evince version is this about?
Comment 2 Bastien Nocera 2017-07-17 14:45:06 UTC
(In reply to André Klapper from comment #1)
> Thanks for reporting this. Which Evince version is this about?

Something old, because we now use libarchive (not that it would support password protected files any better, but it could).
Comment 3 Hanno Böck 2017-07-17 14:56:42 UTC
(In reply to Bastien Nocera from comment #2)
> (In reply to André Klapper from comment #1)
> > Thanks for reporting this. Which Evince version is this about?
> 
> Something old, because we now use libarchive (not that it would support
> password protected files any better, but it could).

Well, "old" as in "the current release", 3.24.0, which still uses command line tools.
I am not sure if password protected cbz files are a thing, so I am not asking to support them. What I'm asking for is not to hang evince and cause CPU load if it sees such a file.

I think going to libarchive is a good move, as it probably prevents all kinds of commandline interaction issues.
Comment 4 Bastien Nocera 2017-07-17 15:07:51 UTC
It throws warnings with master:

(evince:32307): EvinceView-CRITICAL **: ev_page_cache_is_page_cached: assertion 'EV_IS_PAGE_CACHE (cache)' failed

  • #0 _g_log_abort
    at /home/hadess/Projects/jhbuild/glib/glib/gmessages.c line 549
  • #1 g_logv
    at /home/hadess/Projects/jhbuild/glib/glib/gmessages.c line 1357
  • #2 g_log
    at /home/hadess/Projects/jhbuild/glib/glib/gmessages.c line 1398
  • #3 g_return_if_fail_warning
  • #4 ev_page_cache_is_page_cached
    at /home/hadess/Projects/jhbuild/evince/libview/ev-page-cache.c line 765
  • #5 ev_page_accessible_new
    at /home/hadess/Projects/jhbuild/evince/libview/ev-page-accessible.c line 1236
  • #6 initialize_children
    at /home/hadess/Projects/jhbuild/evince/libview/ev-view-accessible.c line 389
  • #7 document_changed_cb
    at /home/hadess/Projects/jhbuild/evince/libview/ev-view-accessible.c line 414
  • #8 ev_view_accessible_set_model
    at /home/hadess/Projects/jhbuild/evince/libview/ev-view-accessible.c line 442
  • #9 ev_view_accessible_new
    at /home/hadess/Projects/jhbuild/evince/libview/ev-view-accessible.c line 498
  • #10 ev_view_get_accessible
    at /home/hadess/Projects/jhbuild/evince/libview/ev-view.c line 7007
  • #11 gail_focus_idle_handler
    from /lib64/libgtk-3.so.0
  • #12 gdk_threads_dispatch
    at /home/hadess/Projects/jhbuild/gtk+-3/gdk/gdk.c line 743
  • #13 g_idle_dispatch
    at /home/hadess/Projects/jhbuild/glib/glib/gmain.c line 5599
  • #14 g_main_dispatch
    at /home/hadess/Projects/jhbuild/glib/glib/gmain.c line 3237
  • #15 g_main_context_dispatch
    at /home/hadess/Projects/jhbuild/glib/glib/gmain.c line 3912
  • #16 g_main_context_iterate
    at /home/hadess/Projects/jhbuild/glib/glib/gmain.c line 3985
  • #17 g_main_context_iteration
    at /home/hadess/Projects/jhbuild/glib/glib/gmain.c line 4046
  • #18 g_application_run
    at /home/hadess/Projects/jhbuild/glib/gio/gapplication.c line 2378
  • #19 main
    at /home/hadess/Projects/jhbuild/evince/shell/main.c line 316

I guess that some pieces of code don't check whether opening the file succeeded. The error reporting could also use some help.
Comment 5 Bastien Nocera 2017-07-17 15:44:58 UTC
What's the password for this test case? unzip can detect that a password is needed to access the data, but libarchive doesn't. It might be thinking that because the file is 0 bytes, it doesn't need to decrypt it ;)
Comment 6 Hanno Böck 2017-07-17 15:49:48 UTC
Sorry, I forgot the password. I'll attach two new files: One cbz with a password and real PNG images inside, one with zero-sized .png-named files inside.

Password in both cases is "linux".
Comment 7 Hanno Böck 2017-07-17 15:50:07 UTC
Created attachment 355764 [details]
password-and-real-images.cbz
Comment 8 Hanno Böck 2017-07-17 15:50:22 UTC
Created attachment 355765 [details]
password-and-zero-size-files.cbz
Comment 9 Bastien Nocera 2017-07-17 16:00:53 UTC
(In reply to Hanno Boeck from comment #6)
> Sorry, I forgot the password. I'll attach two new files: One cbz with a
> password and real PNG images inside, one with zero-sized .png-named files
> inside.
> 
> Password in both cases is "linux".

Thanks. So, yes, libarchive optimises the "zero-length" case.
Comment 10 Bastien Nocera 2017-07-18 14:30:32 UTC
Created attachment 355831 [details] [review]
comics: Add test program for archive handling code

To make it easier to find bugs related to archive handling specifically.
This test program just lists the files in the archive provided, along
with their sizes and whether they are password protected.
Comment 11 Bastien Nocera 2017-07-18 14:30:38 UTC
Created attachment 355832 [details] [review]
comics: Add API to detect whether an archive entry is encrypted

Only implemented and used by the libarchive backend unfortunately.
Comment 12 Bastien Nocera 2017-07-18 14:30:45 UTC
Created attachment 355833 [details] [review]
comics: Add error reporting to comics_document_list()

So that we can know whether a NULL return value is due to an empty file
or a broken file.
Comment 13 Bastien Nocera 2017-07-18 14:30:51 UTC
Created attachment 355834 [details] [review]
comics: Return an error when archive contents are encrypted
Comment 14 Bastien Nocera 2017-07-18 14:30:57 UTC
Created attachment 355835 [details] [review]
comics: Use error returned by comics_document_list()
Comment 15 Bastien Nocera 2017-07-18 14:31:02 UTC
Created attachment 355836 [details] [review]
comics: Throw an error if the mime-type cannot be read
Comment 16 Bastien Nocera 2017-07-18 14:53:31 UTC
Created attachment 355841 [details] [review]
comics: Split off checking whether a file has a supported extension
Comment 17 Bastien Nocera 2017-07-18 14:53:37 UTC
Created attachment 355842 [details] [review]
comics: Check for supported extensions in initial list loop

Instead of looping over all the files once, making a list, then going
over the list once again to check whether those files are supported,
check for support when building the list.

This fixes reporting an error when non-image files are encrypted and
we could read the images just fine, or the separate errors for when the
archive is empty, or there are no supported files in the archive.
Comment 18 Bastien Nocera 2017-07-18 14:55:45 UTC
That's a load of patches. Note that evince will still say that "zip files" aren't supported instead of the error that the backend sends back.
Comment 19 Bastien Nocera 2017-07-18 15:42:53 UTC
Created attachment 355852 [details] [review]
comics: Return an error when archive contents are encrypted

Note that this will request a password and crash when it cannot pass that
information to the EvDocument later. This needs to be fixed in the
evince shell itself.
Comment 20 Bastien Nocera 2017-07-18 15:43:35 UTC
Created attachment 355853 [details] [review]
shell: Fix typo in comment
Comment 21 Bastien Nocera 2017-07-18 15:43:41 UTC
Created attachment 355854 [details] [review]
libdocument: Remove unused has_document_security() function
Comment 22 Bastien Nocera 2017-07-18 15:43:46 UTC
Created attachment 355855 [details] [review]
shell: Fix crash when comics says it's encrypted

Returning an EV_DOCUMENT_ERROR_ENCRYPTED error to the shell should only
trigger a password prompt if the document supports the
EvDocumentSecurity to pass the password to the loader.
Comment 23 Bastien Nocera 2017-07-18 15:45:50 UTC
(In reply to Bastien Nocera from comment #18)
> That's a load of patches. Note that evince will still say that "zip files"
> aren't supported instead of the error that the backend sends back.

That's because I was returning the wrong error code. But when returning the right error code, it would ask for a password we couldn't do anything with, and crash after that. That's what that last patch is about.

And all that for an edge case :/
Comment 24 Bastien Nocera 2017-07-20 00:35:38 UTC
Comment on attachment 355854 [details] [review]
libdocument: Remove unused has_document_security() function

Moved that to another bug, it's not needed for this one, and was incomplete.
Comment 25 Carlos Garcia Campos 2017-07-22 06:37:12 UTC
Review of attachment 355833 [details] [review]:

::: backend/comics/comics-document.c
@@ +75,3 @@
+				     EV_DOCUMENT_ERROR,
+				     EV_DOCUMENT_ERROR_INVALID,
+				     _("File is corrupted"));

Why don't we just propagate the error message from EvArchive? that's what we do in the PDf backend, for example. I guess ev_archive_open_filename() could fail for other reasons.

@@ +94,3 @@
+						     EV_DOCUMENT_ERROR,
+						     EV_DOCUMENT_ERROR_INVALID,
+						     _("File is corrupted"));

Ditto.

@@ +218,2 @@
 	/* Get list of files in archive */
+	cb_files = comics_document_list (comics_document, NULL);

Why aren't you passing an error here?
Comment 26 Carlos Garcia Campos 2017-07-22 06:38:15 UTC
Review of attachment 355835 [details] [review]:

::: backend/comics/comics-document.c
@@ +232,3 @@
 	/* Get list of files in archive */
+	cb_files = comics_document_list (comics_document, error);
+	if (!cb_files)

I see, this should be squashed in previous commit.
Comment 27 Carlos Garcia Campos 2017-07-22 06:48:09 UTC
Review of attachment 355836 [details] [review]:

::: backend/comics/comics-document.c
@@ +222,2 @@
 	mime_type = ev_file_get_mime_type (uri, FALSE, &err);
+	if (mime_type == NULL) {

I know we were already doing this, but I wonder if this can really happen. If we are here is because the document factory found a mime type for the uri and created a document for it. Maybe we can just add an assert here.

@@ +229,3 @@
+				     EV_DOCUMENT_ERROR,
+				     EV_DOCUMENT_ERROR_INVALID,
+				     _("File is not accessible"));

But if not, let just propagate the error message.
Comment 28 Carlos Garcia Campos 2017-07-22 06:50:12 UTC
Review of attachment 355841 [details] [review]:

Ok
Comment 29 Carlos Garcia Campos 2017-07-22 06:56:12 UTC
Review of attachment 355842 [details] [review]:

Great!

::: backend/comics/comics-document.c
@@ -272,3 @@
-		if (has_supported_extension (cb_file, supported_extensions)) {
-                        g_ptr_array_add (comics_document->page_names,
-                                         g_strstrip (g_strdup (cb_file)));

I guess we should do the strip in comics_document_list now.
Comment 30 Carlos Garcia Campos 2017-07-22 06:57:20 UTC
Review of attachment 355852 [details] [review]:

ok
Comment 31 Carlos Garcia Campos 2017-07-22 06:58:09 UTC
Review of attachment 355853 [details] [review]:

No need to submit a patch for this :-P
Comment 32 Carlos Garcia Campos 2017-07-22 06:59:21 UTC
Review of attachment 355855 [details] [review]:

Sure
Comment 33 Bastien Nocera 2017-07-22 12:51:21 UTC
Review of attachment 355833 [details] [review]:

::: backend/comics/comics-document.c
@@ +75,3 @@
+				     EV_DOCUMENT_ERROR,
+				     EV_DOCUMENT_ERROR_INVALID,
+				     _("File is corrupted"));

Because the error message returned by EvArchive are only useful for debug. Running evince with debug messages would allow to gather that if there's ever another reason for the archive not to be opened.

@@ +218,2 @@
 	/* Get list of files in archive */
+	cb_files = comics_document_list (comics_document, NULL);

It's in a separate patch, I'll merge.
Comment 34 Bastien Nocera 2017-07-22 12:56:08 UTC
Review of attachment 355836 [details] [review]:

I wouldn't assert because that's ugly, but I made it propagate the error.
Comment 35 Bastien Nocera 2017-07-22 13:01:14 UTC
Review of attachment 355842 [details] [review]:

::: backend/comics/comics-document.c
@@ -272,3 @@
-		if (has_supported_extension (cb_file, supported_extensions)) {
-                        g_ptr_array_add (comics_document->page_names,
-                                         g_strstrip (g_strdup (cb_file)));

I think we shouldn't be stripping since we use libarchive. We're not parsing command-line outputs anymore, and we can handle leading and trailing spaces just fine :)
Comment 36 Bastien Nocera 2017-07-22 13:02:18 UTC
Created attachment 356165 [details] [review]
comics: Add test program for archive handling code

To make it easier to find bugs related to archive handling specifically.
This test program just lists the files in the archive provided, along
with their sizes and whether they are password protected.
Comment 37 Bastien Nocera 2017-07-22 13:02:24 UTC
Created attachment 356166 [details] [review]
comics: Don't strip filenames in archive

This was useful when parsing command-line outputs but makes no sense
since we switched to using libarchive/unarr, and would actually break
support for filenames in the archive that have leading or trailing
spaces.
Comment 38 Bastien Nocera 2017-07-22 13:02:30 UTC
Created attachment 356167 [details] [review]
comics: Add API to detect whether an archive entry is encrypted

Only implemented and used by the libarchive backend unfortunately.
Comment 39 Bastien Nocera 2017-07-22 13:02:36 UTC
Created attachment 356168 [details] [review]
comics: Add error reporting to comics_document_list()

So that we can know whether a NULL return value is due to an empty file
or a broken file.
Comment 40 Bastien Nocera 2017-07-22 13:02:42 UTC
Created attachment 356169 [details] [review]
comics: Return an error when archive contents are encrypted

Note that this will request a password and crash when it cannot pass that
information to the EvDocument later. This needs to be fixed in the
evince shell itself.
Comment 41 Bastien Nocera 2017-07-22 13:02:48 UTC
Created attachment 356170 [details] [review]
comics: Propagate an error if the mime-type cannot be read

And avoid leaking an unused error.
Comment 42 Bastien Nocera 2017-07-22 13:02:54 UTC
Created attachment 356171 [details] [review]
comics: Split off checking whether a file has a supported extension
Comment 43 Bastien Nocera 2017-07-22 13:03:01 UTC
Created attachment 356172 [details] [review]
comics: Check for supported extensions in initial list loop

Instead of looping over all the files once, making a list, then going
over the list once again to check whether those files are supported,
check for support when building the list.

This fixes reporting an error when non-image files are encrypted and
we could read the images just fine, or the separate errors for when the
archive is empty, or there are no supported files in the archive.
Comment 44 Bastien Nocera 2017-07-22 13:03:08 UTC
Created attachment 356173 [details] [review]
shell: Fix typo in comment
Comment 45 Bastien Nocera 2017-07-22 13:03:14 UTC
Created attachment 356174 [details] [review]
shell: Fix crash when comics says it's encrypted

Returning an EV_DOCUMENT_ERROR_ENCRYPTED error to the shell should only
trigger a password prompt if the document supports the
EvDocumentSecurity to pass the password to the loader.
Comment 46 Bastien Nocera 2017-07-22 13:03:58 UTC
Attachment 356165 [details] pushed as 5e92c9a - comics: Add test program for archive handling code
Attachment 356166 [details] pushed as 9a407f1 - comics: Don't strip filenames in archive
Attachment 356167 [details] pushed as 4cc667c - comics: Add API to detect whether an archive entry is encrypted
Attachment 356168 [details] pushed as 2efa131 - comics: Add error reporting to comics_document_list()
Attachment 356169 [details] pushed as 29747f1 - comics: Return an error when archive contents are encrypted
Attachment 356170 [details] pushed as 14c54a7 - comics: Propagate an error if the mime-type cannot be read
Attachment 356171 [details] pushed as 06c17eb - comics: Split off checking whether a file has a supported extension
Attachment 356172 [details] pushed as 2de9104 - comics: Check for supported extensions in initial list loop
Attachment 356173 [details] pushed as bfeafcc - shell: Fix typo in comment
Attachment 356174 [details] pushed as 1703978 - shell: Fix crash when comics says it's encrypted
Comment 47 Carlos Garcia Campos 2017-07-23 08:35:05 UTC
(In reply to Bastien Nocera from comment #35)
> Review of attachment 355842 [details] [review] [review]:
> 
> ::: backend/comics/comics-document.c
> @@ -272,3 @@
> -		if (has_supported_extension (cb_file, supported_extensions)) {
> -                        g_ptr_array_add (comics_document->page_names,
> -                                         g_strstrip (g_strdup (cb_file)));
> 
> I think we shouldn't be stripping since we use libarchive. We're not parsing
> command-line outputs anymore, and we can handle leading and trailing spaces
> just fine :)

Good point!