summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorrbuj <[email protected]>2022-08-07 23:08:59 +0200
committerLuke from DC <[email protected]>2022-11-17 06:48:44 +0000
commit39ba86c9d50b614483152335aa22ee83ac2af02e (patch)
tree4756aeda48bdf74c87f40a0e484fb0ca42c0aacb /backend
parent6ba899248d5f12c9bafaeba9ba371dd7007a9049 (diff)
downloadatril-39ba86c9d50b614483152335aa22ee83ac2af02e.tar.bz2
atril-39ba86c9d50b614483152335aa22ee83ac2af02e.tar.xz
epub: add fallback for malformed epub files in check_mime_type
Diffstat (limited to 'backend')
-rw-r--r--backend/epub/epub-document.c66
1 files changed, 38 insertions, 28 deletions
diff --git a/backend/epub/epub-document.c b/backend/epub/epub-document.c
index 9840ca3c..b025c630 100644
--- a/backend/epub/epub-document.c
+++ b/backend/epub/epub-document.c
@@ -623,41 +623,51 @@ xml_get_data_from_node(xmlNodePtr node,
static gboolean
check_mime_type(const gchar* uri,GError** error)
{
- GError * err = NULL ;
- const gchar* mimeFromFile = ev_file_get_mime_type(uri,FALSE,&err);
+ GError * err = NULL;
+ const gchar* mimeFromFile;
- gchar* mimetypes[] = {"application/epub+zip","application/x-booki+zip"};
- int typecount = 2;
- if ( !mimeFromFile )
+ mimeFromFile = ev_file_get_mime_type(uri, FALSE, &err);
+ if (mimeFromFile)
{
- if (err) {
- g_propagate_error (error, err);
- }
- else {
- g_set_error_literal (error,
- EV_DOCUMENT_ERROR,
- EV_DOCUMENT_ERROR_INVALID,
- _("Unknown MIME Type"));
- }
- return FALSE;
- }
- else
- {
- int i=0;
- for (i=0; i < typecount ;i++) {
- if ( g_strcmp0(mimeFromFile, mimetypes[i]) == 0 ) {
+ const gchar* mimetypes[] = {"application/epub+zip", "application/x-booki+zip", NULL};
+ guint i;
+
+ for (i = 0; i < g_strv_length (mimetypes); i++) {
+ if (strcmp(mimeFromFile, mimetypes[i]) == 0)
return TRUE;
- }
+ }
+
+ /* fallback for malformed epub files */
+ if (strcmp (mimeFromFile, "application/zip") == 0)
+ {
+ mimeFromFile = ev_file_get_mime_type (uri, TRUE, &err);
+ if (mimeFromFile)
+ {
+ for (i = 0; i < g_strv_length (mimetypes); i++) {
+ if (g_strcmp0(mimeFromFile, mimetypes[i]) == 0)
+ return TRUE;
+ }
+
+ /*We didn't find a match*/
+ g_set_error_literal (error,
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("Not an ePub document"));
+
+ return FALSE;
+ }
}
+ }
- /*We didn't find a match*/
+ if (err)
+ g_propagate_error (error, err);
+ else
g_set_error_literal (error,
- EV_DOCUMENT_ERROR,
- EV_DOCUMENT_ERROR_INVALID,
- _("Not an ePub document"));
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("Unknown MIME Type"));
- return FALSE;
- }
+ return FALSE;
}
static gboolean