summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2026-05-29 13:40:47 -0400
committerVictor Kareh <[email protected]>2026-06-02 16:29:59 -0400
commit054035a7eab8282a6b9e79ca25ec8a4d226ef6b8 (patch)
tree2c1691390d48a07673a5098ddaeec2584d7c7caa
parentf50db4bff9acd01dfc87eccc1c452a0ee54ba89e (diff)
downloadatril-054035a7eab8282a6b9e79ca25ec8a4d226ef6b8.tar.bz2
atril-054035a7eab8282a6b9e79ca25ec8a4d226ef6b8.tar.xz
epub: validate epub content before parsing
Check that the content file exists before attempting to parse it, and handle failures in document title extraction gracefully.
-rw-r--r--backend/epub/epub-document.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/backend/epub/epub-document.c b/backend/epub/epub-document.c
index 4aefb336..91e33faa 100644
--- a/backend/epub/epub-document.c
+++ b/backend/epub/epub-document.c
@@ -1600,13 +1600,17 @@ epub_document_toggle_night_mode(EvDocument *document,gboolean night)
static gchar*
epub_document_set_document_title(gchar *containeruri)
{
- open_xml_document(containeruri);
- gchar *doctitle;
+ if (open_xml_document(containeruri) == FALSE)
+ return NULL;
+
+ gchar *doctitle = NULL;
set_xml_root_node(NULL);
xmlNodePtr title = xml_get_pointer_to_node((xmlChar*)"title",NULL,NULL);
- doctitle = (gchar*)xml_get_data_from_node(title, XML_KEYWORD, NULL);
+ if (title != NULL)
+ doctitle = (gchar*)xml_get_data_from_node(title, XML_KEYWORD, NULL);
+
xml_free_doc();
return doctitle;
@@ -1758,6 +1762,19 @@ epub_document_load (EvDocument* document,
return FALSE;
}
+ gchar *contentOpfPath = g_filename_from_uri(contentOpfUri,NULL,NULL);
+ if (contentOpfPath == NULL || !g_file_test(contentOpfPath, G_FILE_TEST_IS_REGULAR))
+ {
+ g_free (contentOpfPath);
+ g_free (contentOpfUri);
+ g_set_error_literal(error,
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("could not find epub content"));
+ return FALSE;
+ }
+ g_free (contentOpfPath);
+
epub_document->docTitle = epub_document_set_document_title(contentOpfUri);
epub_document->index = setup_document_index(epub_document,contentOpfUri);