File libgepub-CVE-2025-6196.patch of Package libgepub.39493

From 70895c45364ef4ee827b39b2ed1c33723410e94c Mon Sep 17 00:00:00 2001
From: Daniel Garcia Moreno <daniel.garcia@suse.com>
Date: Mon, 7 Apr 2025 10:54:44 +0200
Subject: [PATCH] Fix integer overflow

Fix https://gitlab.gnome.org/GNOME/libgepub/-/issues/18
---
 libgepub/gepub-archive.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libgepub/gepub-archive.c b/libgepub/gepub-archive.c
index 4305a18..733a22c 100644
--- a/libgepub/gepub-archive.c
+++ b/libgepub/gepub-archive.c
@@ -134,7 +134,7 @@ gepub_archive_read_entry (GepubArchive *archive,
 {
     struct archive_entry *entry;
     guchar *buffer;
-    gint size;
+    int64_t size;
     const gchar *_path;
 
     if (path[0] == '/') {
@@ -154,7 +154,20 @@ gepub_archive_read_entry (GepubArchive *archive,
     }
 
     size = archive_entry_size (entry);
+
+    // Validate size
+    if (size > G_MAXSIZE) {
+        gepub_archive_close (archive);
+        return NULL;
+    }
+
+    // Allocate buffer with additional error handling
     buffer = g_malloc0 (size);
+    if (!buffer) {
+        gepub_archive_close (archive);
+        return NULL;
+    }
+
     archive_read_data (archive->archive, buffer, size);
 
     gepub_archive_close (archive);
-- 
2.49.0

openSUSE Build Service is sponsored by