From 3565a5f2de72dd67803a2837834ff6edcafd4904 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Tue, 11 Mar 2025 18:43:04 +0100 Subject: rar: Fix crash with no filename Fix crash if filename retrieval fails, which currently happens with RAR 7.00 directories. An upcoming fix with properly parse those, but it's better not to crash on malformed/unexpected input nonetheless. Part of #527. --- src/fr-command-rar.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/fr-command-rar.c b/src/fr-command-rar.c index 6bb70cd..956b88f 100644 --- a/src/fr-command-rar.c +++ b/src/fr-command-rar.c @@ -163,10 +163,12 @@ parse_name_field (char *line, fdata->encrypted = (line[0] == '*') ? TRUE : FALSE; - if (rar_comm->output_type == FR_COMMAND_RAR_TYPE_RAR5) + if (rar_comm->output_type == FR_COMMAND_RAR_TYPE_RAR5) { + const char *field = get_last_field (line, attribute_field_with_space (line) ? 9 : 8); + /* rar-5 output adds trailing spaces to short file names :( */ - name_field = g_strchomp (g_strdup (get_last_field (line, attribute_field_with_space (line) ? 9 : 8))); - else + name_field = field ? g_strchomp (g_strdup (field)) : NULL; + } else name_field = g_strdup (line + 1); if (name_field == NULL) @@ -246,7 +248,7 @@ process_line (char *line, if (rar_comm->rar4_odd_line || rar_comm->output_type == FR_COMMAND_RAR_TYPE_RAR5) parse_name_field (line, rar_comm); - if (! rar_comm->rar4_odd_line) { + if (! rar_comm->rar4_odd_line && rar_comm->fdata && rar_comm->fdata->full_path) { FileData *fdata; const char *size_field, *ratio_field, *date_field, *time_field, *attr_field; int n_fields; -- cgit v1.2.1