Skip to content
Snippets Groups Projects
Commit bff68ad0 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Check max_files value in extract_files_from_archive() better

Address issue reported by Nightfox via DOVE-Net:
Today I was using the Archive class to extract exactly one file from a zip
file, and I'm a little confused on the exception throwing behavior regarding
the max_files parameter.  When calling extract(), I gave it a filename pattern
and expected exactly 1 file to be extracted, so I also gave a max_files
argument as 1.  It extracted the one file, but it threw an exception with the
error "Error: maximum number of files (1) extracted (after extracting 1 item
successfully)".

Should that be an error condition to throw an exception? I expected 1 file to
be extracted, and that file was extracted successfully.  If I specify max_files
as 2, then it doesn't throw an exception.   
parent 045a33ca
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3195 passed
......@@ -982,6 +982,10 @@ long extract_files_from_archive(const char* archive, const char* outdir, const c
SAFECAT(fpath, pathname);
if(!overwrite && fexist(fpath))
continue;
if(max_files && extracted >= max_files) {
safe_snprintf(error, maxerrlen, "maximum number of files (%lu) extracted", max_files);
break;
}
FILE* fp = fopen(fpath, "wb");
if(fp == NULL) {
char err[256];
......@@ -1010,10 +1014,6 @@ long extract_files_from_archive(const char* archive, const char* outdir, const c
fclose(fp);
if(result != ARCHIVE_EOF)
(void)remove(fpath);
if(max_files && extracted >= max_files) {
safe_snprintf(error, maxerrlen, "maximum number of files (%lu) extracted", max_files);
break;
}
}
archive_read_free(ar);
return extracted;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment