plug-ins: fix reading of FLI files where the filesize is off-by-on

This commit is contained in:
Jacob Boerema 2022-05-16 11:21:57 -04:00
parent ca8eee1755
commit 980e604880
1 changed files with 10 additions and 4 deletions

View File

@ -196,11 +196,17 @@ fli_read_header (FILE *f,
fli_header->height = 200; fli_header->height = 200;
if (actual_size != fli_header->filesize && actual_size >= 0) if (actual_size != fli_header->filesize && actual_size >= 0)
{
/* Older versions of GIMP or other apps may incorrectly finish chunks on
* an odd length, but write filesize as if that last byte was written.
* Don't fail on off-by-one file size. */
if (actual_size + 1 != fli_header->filesize)
{ {
g_warning (_("Incorrect file size in header: %u, should be: %u."), g_warning (_("Incorrect file size in header: %u, should be: %u."),
fli_header->filesize, (guint) actual_size); fli_header->filesize, (guint) actual_size);
fli_header->filesize = actual_size; fli_header->filesize = actual_size;
} }
}
if (fli_header->frames == 0) if (fli_header->frames == 0)
{ {
@ -341,7 +347,7 @@ fli_read_frame (FILE *f,
} }
g_debug ("Chunk offset: %u, chunk size: %u, chunk type: %u", g_debug ("Chunk offset: %u, chunk size: %u, chunk type: %u",
(guint) chunkpos, chunk.size, chunk.magic); (guint) chunkpos, chunk.size, chunk.magic);
if (chunkpos + chunk.size >= fli_header->filesize) if (chunkpos + chunk.size > fli_header->filesize)
{ {
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Invalid chunk size points past end of file!")); _("Invalid chunk size points past end of file!"));