diff --git a/plug-ins/common/file-lnk.c b/plug-ins/common/file-lnk.c index aec2dc384d..ff57abab34 100644 --- a/plug-ins/common/file-lnk.c +++ b/plug-ins/common/file-lnk.c @@ -252,29 +252,33 @@ load_image (GFile *file, /* Length of the filename */ link_size = length - link_pos - 1; - if (link_size > 0) + if (link_size <= 0) { + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + _("Invalid file.")); + fclose (fp); + return NULL; + } + + gchar file_name[link_size]; + + /* Jump to link address and read in the real file name */ + if (fseek (fp, base + link_pos, SEEK_SET) < 0 || + fread (file_name, sizeof (gchar), link_size, fp) != link_size) { - gchar file_name[link_size]; - - /* Jump to link address and read in the real file name */ - if (fseek (fp, base + link_pos, SEEK_SET) < 0 || - fread (file_name, sizeof (gchar), link_size, fp) != link_size) - { - g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), - _("Invalid file.")); - fclose (fp); - return NULL; - } - - file_name[link_size - 1] = '\0'; - image = gimp_file_load (GIMP_RUN_NONINTERACTIVE, - g_file_new_for_path (file_name)); - - if (! image) - g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, - "%s", gimp_pdb_get_last_error (gimp_get_pdb ())); - + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + _("Invalid file.")); + fclose (fp); + return NULL; } + + file_name[link_size - 1] = '\0'; + image = gimp_file_load (GIMP_RUN_NONINTERACTIVE, + g_file_new_for_path (file_name)); + + if (! image) + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "%s", gimp_pdb_get_last_error (gimp_get_pdb ())); + fclose (fp); return image;