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

zip: conform slashes #637

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions mz_zip.c
Expand Up @@ -18,6 +18,7 @@

#include "mz.h"
#include "mz_crypt.h"
#include "mz_os.h"
#include "mz_strm.h"
#ifdef HAVE_BZIP2
# include "mz_strm_bzip.h"
Expand Down Expand Up @@ -787,12 +788,16 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
}

if (err == MZ_OK) {
if (mz_stream_write(stream, filename, filename_length) != filename_length)
char conformed_filename[512];
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to just use MZ_ALLOC here, and if it returns NULL then return MZ_ERROR_MEM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @nmoinvaz, modifications checked in.

strncpy(conformed_filename, filename, sizeof(conformed_filename) - 1);
mz_path_convert_slashes(conformed_filename, MZ_PATH_SLASH_UNIX);

if (mz_stream_write(stream, conformed_filename, filename_length) != filename_length)
err = MZ_WRITE_ERROR;

/* Ensure that directories have a slash appended to them for compatibility */
if (err == MZ_OK && write_end_slash)
err = mz_stream_write_uint8(stream, '/');
err = mz_stream_write_uint8(stream, MZ_PATH_SLASH_UNIX);
}

/* Write ZIP64 extra field first so we can update sizes later if data descriptor not used */
Expand Down