Commit Diff


commit - 5e75cd8aca95a10fde15903eb10d240372767d2f
commit + 914af8516ff3e19ddb584d9df7f789860cb96bde
blob - b08648aa47f637dd6010b5c41db17910f905af7b
blob + 7f5d4845d016fb6307b1bc631ce263c2d333cccb
--- resources/posts/extracting-from-zips.gmi
+++ resources/posts/extracting-from-zips.gmi
@@ -1,5 +1,7 @@
 => /post/inspecting-zips.gmi The first part “Inspecting zip files”
 
+=> //git.omarpolo.com/zip-view/ The code for the whole series; see ‘zipview.c’ for this post in particular.
+
 Edit 2021/08/21: Stefan Sperling (thanks!) noticed an error in the ‘next’ function.  After that I found that a wrong check in ‘next’ caused an invalid memory access.  The ‘next‘ and ‘ls’ functions were corrected.
 
 Now that we know how to navigate inside a zip file let’s see how to extract files from it.  But before looking into the decompression routines (spoiler: we’ll need zlib, so make sure it’s installed) we need to do a bit of refactoring, the reason will be clear in a second.
@@ -316,8 +318,8 @@ Also note the beauty of the CRC: it can be computed ch
 Now, to test all the code written so far:
 
 ```
-% cc zipls.c -o zipls -lz
-% ./zipls star_maker_olaf_stapledon.gpub metadata.txt
+% cc zipview.c -o zipview -lz
+% ./zipview star_maker_olaf_stapledon.gpub metadata.txt
 title: Star Maker
 author: William Olaf Stapledon
 published: 1937
blob - be7afe323f1a6a20853cbf7e3cd5079c6b26a506
blob + bb379cbc30ff69cea24b18dbb12ec9e2d89e1c33
--- resources/posts/inspecting-zips.gmi
+++ resources/posts/inspecting-zips.gmi
@@ -1,7 +1,10 @@
 => /post/extracting-from-zips.gmi  Part two: “Extracting files from zips”
 
-2021/08/20: some edits to improve the code and the commentary.
+=> //git.omarpolo.com/zip-view/ The code for the whole series; see ‘zipls.c’ for this post in particular.
 
+Edit 2021/08/20: some edits to improve the code and the commentary.
+Edit 2021/08/21: stricter while condition for ‘ls’ and added links to the code
+
 Disclaimer: before today I didn’t knew anything about how zip files are structured, so take everything here with a huge grain of salt.  The good news is that the code I wrote seems to be coherent with what I’ve read online and to actually work against some zips files I had around.
 
 Background: I’d like to add support for gempubs to Telescope, the Gemini client I’m writing.  gempubs are basically a directory of text/gemini files plus other assets (metadata.txt and images presumably) all zipped in a single archive.
@@ -172,7 +175,7 @@ ls(uint8_t *zip, size_t len, uint8_t *cd)
 	char		 filename[PATH_MAX];
 
 	end = zip + len;
-	while (cd < end - 4 && memcmp(cd, "\x50\x4b\x01\x02", 4) == 0) {
+	while (cd < end - 46 && memcmp(cd, "\x50\x4b\x01\x02", 4) == 0) {
 		memcpy(&flen, cd + 28, sizeof(flen));
 		memcpy(&xlen, cd + 28 + 2, sizeof(xlen));
 		memcpy(&clen, cd + 28 + 2 + 2, sizeof(xlen));