Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when closing a zip #222

Open
anass114 opened this issue Jan 2, 2024 · 3 comments
Open

Issue when closing a zip #222

anass114 opened this issue Jan 2, 2024 · 3 comments

Comments

@anass114
Copy link

anass114 commented Jan 2, 2024

Hi,

I have an issue when I try to close a zip.
I am downloading and caching files to a std::map. When a certain number of bytes have been downloaded. There is a thread that is launched to process files, adding them in the zip and closing the zip after.

Here is the code I am using :

	if (totalTempSize > 5000000)
	{
		for (auto it : Archives)
		{
			libzippp::ZipArchive z1(it.first);
			z1.setErrorHandlerCallback([](const std::string& message,
				const std::string& strerror,
				int zip_error_code,
				int system_error_code)
				{
					// Handle error here
					MessageBoxA(NULL, message.c_str(), strerror.c_str(), 0);
				});
			if (z1.open(libzippp::ZipArchive::Write))
			{
				z1.setCompressionMethod(STORE);

				for (auto it2 : it.second)
				{
					totalTempSize -= it2.second.size();
					z1.addData(it2.first, it2.second.data(), it2.second.size());
				}
				z1.close();
				it.second.clear();
			}
		}
	}

Randomly, at some moment. The program ends up crashing.
image

I also checked the zip format and see if there is any problem on it. I couldn't find any.

Is there something I can. I have been struggling for days on this.

Thanks

@anass114
Copy link
Author

anass114 commented Jan 2, 2024

I have found one of my mistakes. it2 was destroyed oputside the scope and same for the pointers.
So replacing with :

for (auto &it2 : it.second)
				{
					totalTempSize -= it2.second.size();
					z1.addData(it2.first, it2.second.data(), it2.second.size(),false);
				}

Fixed the problem.

But I am facing a second one :
image

I assumed there was an issue with the zip. But 7zip tests didn't find any problem.

Thanks for help

@anass114
Copy link
Author

anass114 commented Jan 2, 2024

After updating the lib. I Have now the following message.
Zip archive inconsistent
entry 0: invalid WinZip AES extra field

@ctabin
Copy link
Owner

ctabin commented Jan 4, 2024

Hi @anass114,
Please provide a reproducible test case.
The files are written when the archive is closed, so the pointers must remain valid until then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants