(archive_file) Safe optimizations

This commit is contained in:
twinaphex 2019-04-26 12:46:44 +02:00
parent aa156bd804
commit 68ab984603
1 changed files with 8 additions and 18 deletions

View File

@ -644,7 +644,7 @@ bool file_archive_perform_mode(const char *path, const char *valid_exts,
{ {
case ARCHIVE_MODE_UNCOMPRESSED: case ARCHIVE_MODE_UNCOMPRESSED:
if (!filestream_write_file(path, cdata, size)) if (!filestream_write_file(path, cdata, size))
goto error; return false;
break; break;
case ARCHIVE_MODE_COMPRESSED: case ARCHIVE_MODE_COMPRESSED:
@ -658,11 +658,11 @@ bool file_archive_perform_mode(const char *path, const char *valid_exts,
handle.backend = file_archive_get_file_backend(userdata->archive_path); handle.backend = file_archive_get_file_backend(userdata->archive_path);
if (!handle.backend) if (!handle.backend)
goto error; return false;
if (!handle.backend->stream_decompress_data_to_file_init(&handle, if (!handle.backend->stream_decompress_data_to_file_init(&handle,
cdata, csize, size)) cdata, csize, size))
goto error; return false;
do do
{ {
@ -673,17 +673,14 @@ bool file_archive_perform_mode(const char *path, const char *valid_exts,
if (!file_archive_decompress_data_to_file(&handle, if (!file_archive_decompress_data_to_file(&handle,
ret, path, valid_exts, ret, path, valid_exts,
cdata, csize, size, crc32)) cdata, csize, size, crc32))
goto error; return false;
} }
break; break;
default: default:
goto error; return false;
} }
return true; return true;
error:
return false;
} }
/** /**
@ -738,7 +735,7 @@ int file_archive_compressed_read(
{ {
const struct file_archive_file_backend *backend = NULL; const struct file_archive_file_backend *backend = NULL;
int ret = 0; int ret = 0;
struct string_list *str_list = file_archive_filename_split(path); struct string_list *str_list = NULL;
/* Safety check. /* Safety check.
* If optional_filename and optional_filename * If optional_filename and optional_filename
@ -749,10 +746,10 @@ int file_archive_compressed_read(
if (optional_filename && filestream_exists(optional_filename)) if (optional_filename && filestream_exists(optional_filename))
{ {
*length = 0; *length = 0;
string_list_free(str_list);
return 1; return 1;
} }
str_list = file_archive_filename_split(path);
/* We assure that there is something after the '#' symbol. /* We assure that there is something after the '#' symbol.
* *
* This error condition happens for example, when * This error condition happens for example, when
@ -763,7 +760,6 @@ int file_archive_compressed_read(
goto error; goto error;
backend = file_archive_get_file_backend(str_list->elems[0].data); backend = file_archive_get_file_backend(str_list->elems[0].data);
*length = backend->compressed_file_read(str_list->elems[0].data, *length = backend->compressed_file_read(str_list->elems[0].data,
str_list->elems[1].data, buf, optional_filename); str_list->elems[1].data, buf, optional_filename);
@ -841,16 +837,10 @@ const struct file_archive_file_backend* file_archive_get_file_backend(const char
uint32_t file_archive_get_file_crc32(const char *path) uint32_t file_archive_get_file_crc32(const char *path)
{ {
file_archive_transfer_t state; file_archive_transfer_t state;
const struct file_archive_file_backend *backend = file_archive_get_file_backend(path);
struct archive_extract_userdata userdata = {{0}}; struct archive_extract_userdata userdata = {{0}};
bool returnerr = false; bool returnerr = false;
bool contains_compressed = false;
const char *archive_path = NULL; const char *archive_path = NULL;
bool contains_compressed = path_contains_compressed_file(path);
if (!backend)
return 0;
contains_compressed = path_contains_compressed_file(path);
if (contains_compressed) if (contains_compressed)
{ {