static void *unpack_entry_data(unsigned long offset, unsigned long size) { z_stream stream; void *buf = xmalloc(size); memset(&stream, 0, sizeof(stream)); stream.next_out = buf; stream.avail_out = size; stream.next_in = fill(1); stream.avail_in = input_len; inflateInit(&stream); for (;;) { int ret = inflate(&stream, 0); use(input_len - stream.avail_in); if (stream.total_out == size && ret == Z_STREAM_END) break; if (ret != Z_OK) bad_object(offset, "inflate returned %d", ret); stream.next_in = fill(1); stream.avail_in = input_len; } inflateEnd(&stream); return buf; }
static void *unpack_entry_data(unsigned long offset, unsigned long size) { int status; z_stream stream; void *buf = xmalloc(size); memset(&stream, 0, sizeof(stream)); git_inflate_init(&stream); stream.next_out = buf; stream.avail_out = size; do { stream.next_in = fill(1); stream.avail_in = input_len; status = git_inflate(&stream, 0); use(input_len - stream.avail_in); } while (status == Z_OK); if (stream.total_out != size || status != Z_STREAM_END) bad_object(offset, "inflate returned %d", status); git_inflate_end(&stream); return buf; }
static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_base) { unsigned char *p; unsigned long size, c; off_t base_offset; unsigned shift; void *data; obj->idx.offset = consumed_bytes; input_crc32 = crc32(0, Z_NULL, 0); p = fill(1); c = *p; use(1); obj->type = (c >> 4) & 7; size = (c & 15); shift = 4; while (c & 0x80) { p = fill(1); c = *p; use(1); size += (c & 0x7f) << shift; shift += 7; } obj->size = size; switch (obj->type) { case OBJ_REF_DELTA: hashcpy(delta_base->sha1, fill(20)); use(20); break; case OBJ_OFS_DELTA: memset(delta_base, 0, sizeof(*delta_base)); p = fill(1); c = *p; use(1); base_offset = c & 127; while (c & 128) { base_offset += 1; if (!base_offset || MSB(base_offset, 7)) bad_object(obj->idx.offset, "offset value overflow for delta base object"); p = fill(1); c = *p; use(1); base_offset = (base_offset << 7) + (c & 127); } delta_base->offset = obj->idx.offset - base_offset; if (delta_base->offset <= 0 || delta_base->offset >= obj->idx.offset) bad_object(obj->idx.offset, "delta base offset is out of bound"); break; case OBJ_COMMIT: case OBJ_TREE: case OBJ_BLOB: case OBJ_TAG: break; default: bad_object(obj->idx.offset, "unknown object type %d", obj->type); } obj->hdr_size = consumed_bytes - obj->idx.offset; data = unpack_entry_data(obj->idx.offset, obj->size); obj->idx.crc32 = input_crc32; return data; }