1
1
mirror of https://gitlab.gnome.org/GNOME/gimp.git synced 2025-10-05 21:02:42 +02:00

plug-ins: fix memory management and handle multi-file zip.

We should not call archive_entry_free() since man
archive_read_next_header explicitly says that the returned entry is an
internal object:

> This is a convenience wrapper around archive_read_next_header2() that
> reuses an internal struct archive_entry object for each request.

The only reason why it was not crashing is that we were not properly
freeing the archive itself so internal objects were hanging! The man
archive_read says:

> Once you have finished reading data from the archive, you should call
> archive_read_close() to close the archive, then call archive_read_free()
> to release all resources, including all memory allocated by the library.

Therefore this code add archive_read_free() at the end and removes
archive_entry_free().

Furthermore we now verify if the zip archive contains any other file.
Unlike all other compression formats we were supporting until now, zip
is a full multi-file container format and we are always only trying to
read the first file listed in the archive. This likely means that this
file was not meant to be opened this way. In any case, still try to load
the first file as an image, yet raise a warning about the existence of
more files in the archive.
This commit is contained in:
Jehan
2025-09-30 19:57:59 +02:00
parent 7275569079
commit 41035c7589

View File

@@ -1083,6 +1083,7 @@ zip_load (GFile *infile,
if (r != ARCHIVE_OK)
{
archive_read_close (a);
archive_read_free (a);
goto out;
}
@@ -1094,13 +1095,22 @@ zip_load (GFile *infile,
if (r != ARCHIVE_OK)
{
archive_read_close (a);
archive_read_free (a);
goto out;
}
archive_entry_free (entry);
ret = TRUE;
if (archive_read_next_header (a, &entry) != ARCHIVE_EOF)
/* Leave a chance for the load to succeed (in case the first
* file happens to be an image file), yet still warns. This
* procedure expects that the archive contains a single
* file.
*/
g_message (_("This zip archive contains more than one file."));
}
archive_read_close (a);
archive_read_free (a);
}
out: