tfussell / miniz-cpp Goto Github PK
View Code? Open in Web Editor NEWA cross-platform header-only C++14 library for reading and writing ZIP files
License: MIT License
A cross-platform header-only C++14 library for reading and writing ZIP files
License: MIT License
Is there a way to overwrite a file in a zip? Or delete it? Because when using writestr it just creates file with same name in the zip, which later obviously does not work correctly.
So I want to add a save file to an archive. Because that file already exists it just "stacks" the same files on top of each other with the same filename. Is there a way to overwrite the existing file? I don't want to unpack the complete archive because that would take too long for just saving in the application.
Would be nice to have a real documentation instead of guessing what method does what. :)
I ran Valgrind on my program, that at some point uses miniz-cpp.
It raised one error for miniz-cpp, which is the following:
==37967== Conditional jump or move depends on uninitialised value(s)
==37967== at 0x565D9C4: tdefl_find_match (zip_file.hpp:2339)
==37967== by 0x565D9C4: tdefl_compress_normal (zip_file.hpp:2610)
==37967== by 0x565EA34: tdefl_compress (zip_file.hpp:2727)
==37967== by 0x565EBDE: tdefl_compress_buffer (zip_file.hpp:2747)
==37967== by 0x566506B: mz_zip_writer_add_mem_ex (zip_file.hpp:4430)
==37967== by 0x5663B0F: mz_zip_writer_add_mem (zip_file.hpp:4190)
==37967== by 0x566E63D: miniz_cpp::zip_file::writestr(std::string const&, std::string const&) (zip_file.hpp:5514)
==37967== by 0x566E515: miniz_cpp::zip_file::write(std::string const&, std::string const&) (zip_file.hpp:5504)
I don't think I have the latest code of miniz-cpp so I also put the line here:
}
if (!dist) break; q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; p = s; probe_len = 32;
do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
(TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) );
if (!probe_len)
{
Tracking the origin gives:
==44853== Conditional jump or move depends on uninitialised value(s)
==44853== at 0x564B8A2: tdefl_find_match (zip_file.hpp:2338)
==44853== by 0x564B8A2: tdefl_compress_normal (zip_file.hpp:2610)
==44853== by 0x564C8F5: tdefl_compress (zip_file.hpp:2727)
==44853== by 0x564CA9F: tdefl_compress_buffer (zip_file.hpp:2747)
==44853== by 0x5652F2C: mz_zip_writer_add_mem_ex (zip_file.hpp:4430)
==44853== by 0x56519D0: mz_zip_writer_add_mem (zip_file.hpp:4190)
==44853== by 0x565C4FF: miniz_cpp::zip_file::writestr(std::string const&, std::string const&) (zip_file.hpp:5514)
==44853== by 0x565C3D7: miniz_cpp::zip_file::write(std::string const&, std::string const&) (zip_file.hpp:5504)
...
==44853== Uninitialised value was created by a heap allocation
==44853== at 0x4A37ECB: malloc (vg_replace_malloc.c:307)
==44853== by 0x56422AB: def_alloc_func (zip_file.hpp:1054)
==44853== by 0x5652C34: mz_zip_writer_add_mem_ex (zip_file.hpp:4375)
==44853== by 0x56519D0: mz_zip_writer_add_mem (zip_file.hpp:4190)
==44853== by 0x565C4FF: miniz_cpp::zip_file::writestr(std::string const&, std::string const&) (zip_file.hpp:5514)
==44853== by 0x565C3D7: miniz_cpp::zip_file::write(std::string const&, std::string const&) (zip_file.hpp:5504)
...
==44853==
It would be great if you can solve this issue π
miniz-cpp is based on an old version of zlib/minizip and contains security vulnerabilities. See this example/failing test here: cleeus@d233931
I understand that this project is not in active development but it would be good to point this out in the README, otherwise this code might end up in critical code paths (and it probably alread has). There is a modern, well maintained version of minizip in https://github.com/nmoinvaz/minizip.
In line 518, mz_uint64_t
is defined as unsigned long long.
However, std::uint64_t
on my platform (Linux 64-bit Debian 11) is defined as unsigned long
.
This leads to errors on multiple lines.
Calling "extractall" on a zip file doesn't create folders which exist in the archive, therefore not extracting file that exist within those folders. I would guess this is a limitation of fstream. For what it's worth, this was seen on Windows 7.
Here is the error :
zip_file.hpp:5611:30: error: invalid conversion from βstd::size_t ()(void, uint64_t, const void*, std::size_t) {aka long unsigned int ()(void, long unsigned int, const void*, long unsigned int)}β to βmz_file_write_func {aka long unsigned int ()(void, long long unsigned int, const void*, long unsigned int)}β [-fpermissive]
archive_->m_pWrite = &detail::write_callback;
build and works well on macOS 10.14, clang v10
On line 5980 you use std::strlen
. The namespaced version of this function is not defined in "string.h"
, only in <cstring>
.
This leads to a compilation error.
Hi,
Does this lib support MacOS symlink as zip command do (--symlink option) ?
Thanks
Seems like all function declarations should be marked as static
for correct linking from multiple translation units.
Could you provide an example on how to read actual data?
For example, use the zip command to compress a text file:
zip test.zip test.txt
And then your example would write on screen the test.txt original content.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.