Fix loading of archived content with file names containing '#' characters

This commit is contained in:
jdgleaver 2021-06-03 16:40:13 +01:00
parent d8a5505204
commit b5df2b883a

View File

@ -90,38 +90,44 @@ const char *path_get_archive_delim(const char *path)
if (!last_slash) if (!last_slash)
return NULL; return NULL;
/* Find delimiter position */ /* Find delimiter position
delim = strrchr(last_slash, '#'); * > Since filenames may contain '#' characters,
* must loop until we find the first '#' that
* is directly *after* a compression extension */
delim = strchr(last_slash, '#');
if (!delim) while (delim)
return NULL;
/* Check whether this is a known archive type
* > Note: The code duplication here is
* deliberate, to maximise performance */
if (delim - last_slash > 4)
{ {
strlcpy(buf, delim - 4, sizeof(buf)); /* Check whether this is a known archive type
buf[4] = '\0'; * > Note: The code duplication here is
* deliberate, to maximise performance */
if (delim - last_slash > 4)
{
strlcpy(buf, delim - 4, sizeof(buf));
buf[4] = '\0';
string_to_lower(buf); string_to_lower(buf);
/* Check if this is a '.zip', '.apk' or '.7z' file */ /* Check if this is a '.zip', '.apk' or '.7z' file */
if (string_is_equal(buf, ".zip") || if (string_is_equal(buf, ".zip") ||
string_is_equal(buf, ".apk") || string_is_equal(buf, ".apk") ||
string_is_equal(buf + 1, ".7z")) string_is_equal(buf + 1, ".7z"))
return delim; return delim;
} }
else if (delim - last_slash > 3) else if (delim - last_slash > 3)
{ {
strlcpy(buf, delim - 3, sizeof(buf)); strlcpy(buf, delim - 3, sizeof(buf));
buf[3] = '\0'; buf[3] = '\0';
string_to_lower(buf); string_to_lower(buf);
/* Check if this is a '.7z' file */ /* Check if this is a '.7z' file */
if (string_is_equal(buf, ".7z")) if (string_is_equal(buf, ".7z"))
return delim; return delim;
}
delim++;
delim = strchr(delim, '#');
} }
return NULL; return NULL;