git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] archive-zip: support UTF-8 paths

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Sep 18, 2012, 19:46 UTC
Message-ID
<5058CFB0.6040506@lsrfire.ath.cx>
In-Reply-To
<5058CE49.3070108@lsrfire.ath.cx>

Set general purpose flag 11 if we encounter a path that contains non-ASCII characters. We assume that all paths are given as UTF-8; no conversion is done.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
Changes from previous version: Stop using has_non_ascii(), which does
slightly too much for our purposes, and split off creator version
change into a separate patch.
 archive-zip.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/archive-zip.c b/archive-zip.c
index f5af81f..0f763e8 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "archive.h"
 #include "streaming.h"
+#include "utf8.h"
 
 static int zip_date;
 static int zip_time;
@@ -16,7 +17,8 @@ static unsigned int zip_dir_offset;
 static unsigned int zip_dir_entries;
 
 #define ZIP_DIRECTORY_MIN_SIZE	(1024 * 1024)
-#define ZIP_STREAM (8)
+#define ZIP_STREAM	(1 <<  3)
+#define ZIP_UTF8	(1 << 11)
 
 struct zip_local_header {
 	unsigned char magic[4];
@@ -164,6 +166,17 @@ static void set_zip_header_data_desc(struct zip_local_header *header,
 	copy_le32(header->size, size);
 }
 
+static int has_only_ascii(const char *s)
+{
+	for (;;) {
+		int c = *s++;
+		if (c == '\0')
+			return 1;
+		if (!isascii(c))
+			return 0;
+	}
+}
+
 #define STREAM_BUFFER_SIZE (1024 * 16)
 
 static int write_zip_entry(struct archiver_args *args,
@@ -187,6 +200,13 @@ static int write_zip_entry(struct archiver_args *args,
 
 	crc = crc32(0, NULL, 0);
 
+	if (!has_only_ascii(path)) {
+		if (is_utf8(path))
+			flags |= ZIP_UTF8;
+		else
+			warning("Path is not valid UTF-8: %s", path);
+	}
+
 	if (pathlen > 0xffff) {
 		return error("path too long (%d chars, SHA1: %s): %s",
 				(int)pathlen, sha1_to_hex(sha1), path);
-- 
1.7.12
Previous: René ScharfeNext: René Scharfe
Message 13 of 21 in “git archive --format zip utf-8 issues”
  1. Sven StrickrothAug 10, 2012
  2. Junio C HamanoAug 10, 2012
  3. Sven StrickrothAug 10, 2012
  4. René ScharfeAug 11, 2012
  5. Junio C HamanoAug 12, 2012
  6. René ScharfeAug 11, 2012
  7. Sven StrickrothAug 11, 2012
  8. Jeff KingAug 30, 2012
  9. René ScharfeSep 4, 2012
  10. Junio C HamanoSep 4, 2012
  11. René ScharfeSep 5, 2012
  12. René ScharfeSep 18, 2012
  13. 1/2 archive-zip: support UTF-8 pathsRené Scharfe, Sep 18, 2012
  14. 2/2 archive-zip: declare creator to be Unix for UTF-8 pathsRené Scharfe, Sep 18, 2012
  15. René ScharfeSep 18, 2012
  16. Junio C HamanoSep 18, 2012
  17. René ScharfeSep 20, 2012
  18. René ScharfeSep 24, 2012
  19. Junio C HamanoSep 24, 2012
  20. 3/2 archive-zip: write extended timestampRené Scharfe, Sep 24, 2012
  21. Junio C HamanoAug 12, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.