From 20dd7fdee5edabd5c83e05b2a37db45c8faf8d37 Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Sat, 20 Dec 2025 10:40:17 -0500 Subject: [PATCH] plug-ins: Check for failure when reading uncompressed psp channels When we fail to read enough bytes when reading uncompressed psp channels, return with an error. The error message was copied from the PSD reader so this should not be affected by the string freeze. (cherry picked from commit bafb005637d37b2df825328a6891e5ca5502f5e3) --- plug-ins/common/file-psp.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plug-ins/common/file-psp.c b/plug-ins/common/file-psp.c index 28d9e1b3ac..9004998ab6 100644 --- a/plug-ins/common/file-psp.c +++ b/plug-ins/common/file-psp.c @@ -1613,9 +1613,14 @@ read_channel_data (FILE *f, { guchar *p, *q; - fread (buf, width, 1, f); + if (fread (buf, 1, width, f) != width) + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + _("Error reading data. Most likely unexpected end of file.")); + return -1; + } /* Contrary to what the PSP specification seems to suggest - scanlines are not stored on a 4-byte boundary. */ + scanlines are not stored on a 4-byte boundary. */ p = buf; q = pixels[y] + offset; for (i = 0; i < width; i++) @@ -1631,9 +1636,14 @@ read_channel_data (FILE *f, { guint16 *p, *q; - fread (buf, width * ia->bytes_per_sample, 1, f); + if (fread (buf, ia->bytes_per_sample, width, f) != width) + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + _("Error reading data. Most likely unexpected end of file.")); + return -1; + } /* Contrary to what the PSP specification seems to suggest - scanlines are not stored on a 4-byte boundary. */ + scanlines are not stored on a 4-byte boundary. */ p = (guint16 *) buf; q = (guint16 *) (pixels[y] + offset); for (i = 0; i < width; i++)