Skip to content

Poco::Zip - Check archive consistency before extracting #4807

Merged
matejk merged 5 commits intopocoproject:mainfrom
nyashbox:fix/check_consistency_before_extracting
Dec 27, 2024
Merged

Poco::Zip - Check archive consistency before extracting #4807
matejk merged 5 commits intopocoproject:mainfrom
nyashbox:fix/check_consistency_before_extracting

Conversation

@nyashbox
Copy link
Copy Markdown
Contributor

@nyashbox nyashbox commented Dec 3, 2024

Fixes #4623

This is by far the best solution I've come up with. When decompressing all files, archive will be checked for consistency, but when decompressing single file, user should check archive manually. Example of the single file decompression with consistency check can be seen below (Original taken from the POCO Zip User Guide)

std::ifstream inp("test.zip", std::ios::binary);
poco_assert (inp);
ZipArchive arch(inp);

// Check consistency before going further
try 
{
    arch.checkConsistency();
}
catch (const ZipException &e) 
{
    // Handle error here
}

ZipArchive::FileHeaders::const_iterator it = arch.findHeader("data/hello.txt");
poco_assert (it != arch.headerEnd());
inp.clear();
ZipInputStream zipin(inp, it->second);
std::ostringstream out(std::ios::binary);
Poco::StreamCopier::copyStream(zipin, out);

There are some other solutions I've considered:

  • Put consistency check in ZipArchive's constructors. But I've decided to refrain from it due to possible unforeseen consequences (and because it's less explicit than calling actual method).
  • Add higher-level API. This could simplify, for example, extracting single file (IMHO wiki example looks a little bit too long and dubious for such a common task), and also hide consistency checks.

@aleks-f aleks-f changed the title Poco::Zip - Check archive constistency before extracting Poco::Zip - Check archive consistency before extracting Dec 3, 2024
@aleks-f aleks-f added this to the Release 1.15.0 milestone Dec 3, 2024
@aleks-f aleks-f requested a review from matejk December 3, 2024 23:25
Copy link
Copy Markdown
Contributor

@matejk matejk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to make it possible to ignore consistency check in case a user would desire to get the file out from the archive anyway?

@nyashbox
Copy link
Copy Markdown
Contributor Author

I think it absolutely makes sense. Somehow I've missed this idea :(

@matejk
Copy link
Copy Markdown
Contributor

matejk commented Dec 12, 2024

@nyashbox, will you update the PR with optional consistency check?

@matejk matejk merged commit a8bac05 into pocoproject:main Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Poco::Zip library should check consistency of archives before extracting

3 participants