Don't use strlen on comments, use 0 as ZIP_FL_NAME_GUESS (is default)
--HG--
branch : HEAD
diff --git a/lib/zip.h b/lib/zip.h
index 205d9e0..e2f0723 100644
--- a/lib/zip.h
+++ b/lib/zip.h
@@ -73,9 +73,9 @@
#define ZIP_FL_RECOMPRESS 16 /* force recompression of data */
#define ZIP_FL_ENCRYPTED 32 /* read encrypted data
(implies ZIP_FL_COMPRESSED) */
+#define ZIP_FL_NAME_GUESS 0 /* guess name encoding (is default) */
#define ZIP_FL_NAME_RAW 64 /* get unmodified name */
-#define ZIP_FL_NAME_GUESS 128 /* guess name encoding */
-#define ZIP_FL_NAME_STRICT 256 /* follow specification strictly */
+#define ZIP_FL_NAME_STRICT 128 /* follow specification strictly */
/* archive global flags flags */
diff --git a/lib/zip_get_archive_comment.c b/lib/zip_get_archive_comment.c
index a2e219b..0a3589b 100644
--- a/lib/zip_get_archive_comment.c
+++ b/lib/zip_get_archive_comment.c
@@ -60,10 +60,11 @@
if (((flags & ZIP_FL_NAME_STRICT) && (za->cdir->comment_type != ZIP_ENCODING_ASCII))
|| (za->cdir->comment_type == ZIP_ENCODING_CP437)) {
if (za->cdir->comment_converted == NULL)
- za->cdir->comment_converted = _zip_cp437_to_utf8(ret, za->cdir->comment_len, &za->error);
+ za->cdir->comment_converted = _zip_cp437_to_utf8(ret, za->cdir->comment_len,
+ &za->cdir->comment_converted_len, &za->error);
ret = za->cdir->comment_converted;
if (lenp != NULL)
- *lenp = strlen(ret);
+ *lenp = za->cdir->comment_converted_len;
}
return ret;
diff --git a/lib/zip_get_file_comment.c b/lib/zip_get_file_comment.c
index fc8c1ae..ee71609 100644
--- a/lib/zip_get_file_comment.c
+++ b/lib/zip_get_file_comment.c
@@ -77,10 +77,11 @@
if (((flags & ZIP_FL_NAME_STRICT) && (za->cdir->entry[idx].fc_type != ZIP_ENCODING_ASCII))
|| (za->cdir->entry[idx].fc_type == ZIP_ENCODING_CP437)) {
if (za->cdir->entry[idx].comment_converted == NULL)
- za->cdir->entry[idx].comment_converted = _zip_cp437_to_utf8(ret, za->cdir->entry[idx].settable.comment_len, &za->error);
+ za->cdir->entry[idx].comment_converted = _zip_cp437_to_utf8(ret, za->cdir->entry[idx].settable.comment_len,
+ &za->cdir->entry[idx].comment_converted_len, &za->error);
ret = za->cdir->entry[idx].comment_converted;
if (lenp != NULL)
- *lenp = strlen(ret);
+ *lenp = za->cdir->entry[idx].comment_converted_len;
}
return ret;
diff --git a/lib/zip_get_name.c b/lib/zip_get_name.c
index 4cef50d..7c3f7b9 100644
--- a/lib/zip_get_name.c
+++ b/lib/zip_get_name.c
@@ -90,7 +90,7 @@
if (((flags & ZIP_FL_NAME_STRICT) && (za->cdir->entry[idx].fn_type != ZIP_ENCODING_ASCII))
|| (za->cdir->entry[idx].fn_type == ZIP_ENCODING_CP437)) {
if (za->cdir->entry[idx].filename_converted == NULL)
- za->cdir->entry[idx].filename_converted = _zip_cp437_to_utf8(ret, strlen(ret), error);
+ za->cdir->entry[idx].filename_converted = _zip_cp437_to_utf8(ret, strlen(ret), NULL, error);
ret = za->cdir->entry[idx].filename_converted;
}
diff --git a/lib/zip_utf-8.c b/lib/zip_utf-8.c
index 28173b1..ab49169 100644
--- a/lib/zip_utf-8.c
+++ b/lib/zip_utf-8.c
@@ -197,13 +197,16 @@
zip_uint8_t *
_zip_cp437_to_utf8(const zip_uint8_t * const cp437buf, zip_uint32_t len,
- struct zip_error *error)
+ zip_uint32_t *utf8_lenp, struct zip_error *error)
{
zip_uint8_t *utf8buf;
zip_uint32_t buflen, i, offset;
- if (len == 0)
+ if (len == 0) {
+ if (utf8_lenp)
+ *utf8_lenp = 0;
return NULL;
+ }
buflen = 1;
for (i=0; i<len; i++)
@@ -220,5 +223,7 @@
utf8buf+offset);
utf8buf[buflen-1] = 0;
+ if (utf8_lenp)
+ *utf8_lenp = buflen-1;
return utf8buf;
}
diff --git a/lib/zipint.h b/lib/zipint.h
index 2118e6d..7026e6b 100644
--- a/lib/zipint.h
+++ b/lib/zipint.h
@@ -263,21 +263,23 @@
char *filename_converted; /* file name (autoconverted) */
unsigned short fc_type; /* file comment encoding (autorecognition) */
char *comment_converted; /* file comment (autoconverted) */
+ zip_uint32_t comment_converted_len; /* file comment length (autoconverted) */
struct zip_dirent_settable settable;
};
/* zip archive central directory */
struct zip_cdir {
- struct zip_dirent *entry; /* directory entries */
- int nentry; /* number of entries */
+ struct zip_dirent *entry; /* directory entries */
+ int nentry; /* number of entries */
- unsigned int size; /* size of central direcotry */
- unsigned int offset; /* offset of central directory in file */
- char *comment; /* zip archive comment */
- unsigned short comment_len; /* length of zip archive comment */
- unsigned short comment_type; /* archive comment encoding (autorecognition) */
- char *comment_converted; /* archive comment (autoconverted) */
+ unsigned int size; /* size of central direcotry */
+ unsigned int offset; /* offset of central directory in file */
+ char *comment; /* zip archive comment */
+ unsigned short comment_len; /* length of zip archive comment */
+ unsigned short comment_type; /* archive comment encoding (autorecognition) */
+ char *comment_converted; /* archive comment (autoconverted) */
+ zip_uint32_t comment_converted_len; /* archive comment length (autoconverted) */
};
@@ -351,7 +353,7 @@
enum zip_encoding_type _zip_guess_encoding(const zip_uint8_t * const,
zip_uint32_t);
zip_uint8_t *_zip_cp437_to_utf8(const zip_uint8_t * const, zip_uint32_t,
- struct zip_error *error);
+ zip_uint32_t *, struct zip_error *error);
struct zip *_zip_open(const char *, FILE *, int, int, int *);