Expected behavior
Data that was successfully compressed using Poco::Zip::Compress should be successfully decompressed by Poco::Zip::Decompress. If Poco::Zip::Compress is not able to correctly compress the data, it should throw an exception.
Actual behavior
Poco::Zip::Compress succeeds, but Poco::Zip::Decompress throws an exception:
ErrorDelegateThrower::doThrow(): CRC mismatch. Corrupt file: C:\source\dev\build\release\C++\SvnRev\ReleaseDev\dummy_zipped.bin
ErrorDelegateThrower::doThrow(): Unknown Exception
Error: Zip: Unknown Exception
Steps to reproduce the problem
#include "stdafx.h"
#include <Poco/Delegate.h>
#include <Poco/Zip/Compress.h>
#include <Poco/Zip/Decompress.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
struct ErrorDelegateThrower;
using ErrorDelegate = Poco::Delegate<ErrorDelegateThrower, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>;
struct ErrorDelegateThrower: public ErrorDelegate {
ErrorDelegateThrower()
: ErrorDelegate(this, &ErrorDelegateThrower::dothrow)
{
}
void dothrow(const void* src, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>& s)
{
std::cout << "ErrorDelegateThrower::doThrow(): " << s.second << '\n';
throw std::runtime_error("Zip: " + s.second);
}
};
int main(int /* unreferenced argc */, char* argv[])
{
try {
std::string path = argv[0];
path = path.substr(0, path.rfind('\\'));
{
std::cout << "Preparing a large file with random data...\n";
srand(0);
std::string data(5.25*1024*1024*1024 /*5.25GB*/, char(0));
for(int d = 0; d<data.size(); ++d)
data[d] = char(rand());
std::ofstream dummy;
dummy.open(path + "/dummy.bin", std::ios_base::binary | std::ios_base::out);
if (!dummy.good())
throw std::runtime_error("failed to open dummy file");
dummy.write(data.data(), data.size());
dummy.close();
}
{
std::cout << "Compressing...\n";
std::ofstream output;
output.open(path + "/dummy.zip", std::ios_base::binary | std::ios_base::out);
if (!output.good())
throw std::runtime_error("failed to open output zip file");
Poco::Zip::Compress zip(output, false);
zip.addFile(path + "/dummy.bin", "dummy_zipped.bin", Poco::Zip::ZipCommon::CM_STORE);
zip.close();
output.close();
}
{
std::cout << "Decompressing...\n";
std::ifstream input;
input.open(path + "/dummy.zip", std::ios_base::binary | std::ios_base::in);
if (!input.good())
throw std::runtime_error("failed to open zip file");
Poco::Zip::Decompress zip(input, path);
ErrorDelegateThrower t;
zip.EError += t;
zip.decompressAllFiles();
input.close();
}
}
catch (const Poco::Exception& e) {
std::cout << "Poco error: " << e.displayText() << "\n";
}
catch (const std::exception& e) {
std::cout << "Error: " << e.what() << "\n";
}
return 0;
}
POCO version
poco-poco-1.9.0-release
Compiler and version
Microsoft (R) C/C++ Optimizing Compiler Version 19.20.27027.1 for x86
Operating system and version
Microsoft Windows [Version 10.0.17134.523]
Other relevant information
- Decompression succeeds if the
forceZip64 flag is set during compression.
- 7z doesn't seem to find any problems.
- After unzipping with 7z, the file seems to be fine:
$ cat dummy.crc
Generated by: cfv (v1.18.3)
Generated at: Thu, 24 Jan 2019 08:38:28
Find it at: http://cfv.sourceforge.net/
Filename Filesize CRC-32 Description
dummy.bin 5,637,144,576 4242ea04
dummy_zipped.bin 5,637,144,576 4242ea04
Count of files: 2
Total of sizes: 11,274,289,152
$ md5sum.exe dummy.bin dummy_zipped.bin
8fe20a0a3e6fded2b545d087bfd6e7f4 *dummy.bin
8fe20a0a3e6fded2b545d087bfd6e7f4 *dummy_zipped.bin
- A zip (store compression) created with 7z of the same file can be decompressed successfully.
Expected behavior
Data that was successfully compressed using
Poco::Zip::Compressshould be successfully decompressed byPoco::Zip::Decompress. IfPoco::Zip::Compressis not able to correctly compress the data, it should throw an exception.Actual behavior
Poco::Zip::Compresssucceeds, butPoco::Zip::Decompressthrows an exception:Steps to reproduce the problem
POCO version
poco-poco-1.9.0-release
Compiler and version
Microsoft (R) C/C++ Optimizing Compiler Version 19.20.27027.1 for x86
Operating system and version
Microsoft Windows [Version 10.0.17134.523]
Other relevant information
forceZip64flag is set during compression.