summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2022-08-07 23:08:59 +0200
committerraveit65 <[email protected]>2023-04-28 21:14:08 +0200
commitc585b945d27e883908c437d12aa9c453db2143f4 (patch)
tree33770e0625ae5e819445e44df52bb910814fb939
parent9f5d7343f79f6ff8295884df3229bc6696b4386c (diff)
downloadatril-c585b945d27e883908c437d12aa9c453db2143f4.tar.bz2
atril-c585b945d27e883908c437d12aa9c453db2143f4.tar.xz
epub: add fallback for malformed epub files in check_mime_type
-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 385d2fea..451c8846 100644
--- a/backend/epub/epub-document.c
+++ b/backend/epub/epub-document.c
@@ -625,41 +625,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