-
-
Notifications
You must be signed in to change notification settings - Fork 484
Closed
Description
fast "dirty" code for reproducing the issue. I'm not sure that I've used API properly. I'm creating zip files with 65534, 65536 and 65535 empty files inside. 65535 doesn't work for some reason. 7-zip can open result zip without any errors
#include <mz.h>
#include <mz_os.h>
#include <mz_strm.h>
#include <mz_strm_os.h>
#include <mz_zip.h>
#include <mz_zip_rw.h>
#include <cstdio>
#include <ctime>
#include <string>
int write_archive(const char* archive_filename, const std::size_t number_of_files) {
void* zip_writer = nullptr;
const char* path = archive_filename;
mz_zip_writer_create(&zip_writer);
if (mz_zip_writer_open_file(zip_writer, path, 0, 0) != MZ_OK) {
mz_zip_writer_delete(&zip_writer);
std::printf("Couldn't open zip for writing");
return -1;
}
for (std::size_t i = 0; i < number_of_files; ++i) {
const auto filename = std::to_string(i);
mz_zip_file file_info = { 0 };
file_info.filename = filename.c_str();
file_info.modified_date = std::time(nullptr);
file_info.version_madeby = MZ_VERSION_MADEBY;
file_info.compression_method = MZ_COMPRESS_METHOD_STORE;
file_info.flag = MZ_ZIP_FLAG_UTF8;
if (mz_zip_writer_entry_open(zip_writer, &file_info) != MZ_OK) {
std::printf("Couldn't open entry");
return -2;
}
if (mz_zip_writer_entry_close(zip_writer) != MZ_OK) {
std::printf("Couldn't close entry");
return -3;
}
}
if (mz_zip_writer_close(zip_writer) != MZ_OK) {
std::printf("Couldn't close writer");
return -4;
}
mz_zip_writer_delete(&zip_writer);
return 0;
}
bool can_archive_be_opened(const char* path) {
void* zip_reader = nullptr;
void* file_stream = nullptr;
mz_zip_reader_create(&zip_reader);
mz_stream_os_create(&file_stream);
auto err = mz_stream_os_open(file_stream, path, MZ_OPEN_MODE_READ);
if (err == MZ_OK) {
err = mz_zip_reader_open(zip_reader, file_stream);
if (err == MZ_OK) {
mz_zip_reader_close(zip_reader);
}
}
mz_stream_os_delete(&file_stream);
mz_zip_reader_delete(&zip_reader);
return err == MZ_OK;
}
int main() {
for (std::size_t i : {65534, 65536, 65535})
{
const auto filename = "test" + std::to_string(i) + ".zip";
const auto write_result = write_archive(filename.c_str(), i);
if (write_result != 0)
return write_result;
const auto read_result = can_archive_be_opened(filename.c_str());
if (!read_result) {
std::printf("Can't open %s", filename.c_str());
return -5;
}
}
}
nmoinvaz
Metadata
Metadata
Assignees
Labels
No labels