| 1721 | } |
| 1722 | |
| 1723 | static void *unpack_compressed_entry(struct packed_git *p, |
| 1724 | struct pack_window **w_curs, |
| 1725 | off_t curpos, |
| 1726 | size_t size) |
| 1727 | { |
| 1728 | int st; |
| 1729 | git_zstream stream; |
| 1730 | unsigned char *buffer, *in; |
| 1731 | |
| 1732 | buffer = xmallocz_gently(size); |
| 1733 | if (!buffer) |
| 1734 | return NULL; |
| 1735 | memset(&stream, 0, sizeof(stream)); |
| 1736 | stream.next_out = buffer; |
| 1737 | stream.avail_out = size + 1; |
| 1738 | |
| 1739 | git_inflate_init(&stream); |
| 1740 | do { |
| 1741 | in = use_pack(p, w_curs, curpos, &stream.avail_in); |
| 1742 | stream.next_in = in; |
| 1743 | /* |
| 1744 | * Note: we must ensure the window section returned by |
| 1745 | * use_pack() will be available throughout git_inflate()'s |
| 1746 | * unlocked execution. Please refer to the comment at |
| 1747 | * get_size_from_delta() to see how this is done. |
| 1748 | */ |
| 1749 | obj_read_unlock(); |
| 1750 | st = git_inflate(&stream, Z_FINISH); |
| 1751 | obj_read_lock(); |
| 1752 | if (!stream.avail_out) |
| 1753 | break; /* the payload is larger than it should be */ |
| 1754 | curpos += stream.next_in - in; |
| 1755 | } while (st == Z_OK || st == Z_BUF_ERROR); |
| 1756 | git_inflate_end(&stream); |
| 1757 | if ((st != Z_STREAM_END) || stream.total_out != size) { |
| 1758 | free(buffer); |
| 1759 | return NULL; |
| 1760 | } |
| 1761 | |
| 1762 | /* versions of zlib can clobber unconsumed portion of outbuf */ |
| 1763 | buffer[size] = '\0'; |
| 1764 | |
| 1765 | return buffer; |
| 1766 | } |
| 1767 | |
| 1768 | static void write_pack_access_log(struct packed_git *p, off_t obj_offset) |
| 1769 | { |
no test coverage detected