packfile: correct zlib buffer handling
[gitweb.git] / packfile.c
index eab7542487a194ecd25708f906e66c40e1bed336..d55569921793ed8f16efef2d6908740888a06b4d 100644 (file)
@@ -1422,6 +1422,9 @@ static void *unpack_compressed_entry(struct packed_git *p,
                return NULL;
        }
 
+       /* versions of zlib can clobber unconsumed portion of outbuf */
+       buffer[size] = '\0';
+
        return buffer;
 }
 
@@ -1743,7 +1746,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
                       sha1[0], sha1[1], sha1[2], lo, hi, p->num_objects);
 
        while (lo < hi) {
-               unsigned mi = (lo + hi) / 2;
+               unsigned mi = lo + (hi - lo) / 2;
                int cmp = hashcmp(index + mi * stride, sha1);
 
                if (debug_lookup)