| 54 | } |
| 55 | |
| 56 | static void zlib_post_call(git_zstream *s, int status) |
| 57 | { |
| 58 | size_t bytes_consumed; |
| 59 | size_t bytes_produced; |
| 60 | |
| 61 | bytes_consumed = s->z.next_in - s->next_in; |
| 62 | bytes_produced = s->z.next_out - s->next_out; |
| 63 | /* |
| 64 | * zlib's total_out/total_in are uLong which may wrap for >4GB. |
| 65 | * We track our own totals and verify only the low bits match. |
| 66 | */ |
| 67 | if ((s->z.total_out & ULONG_MAX_VALUE) != |
| 68 | ((zlib_uLong_cap(s->total_out) + bytes_produced) & ULONG_MAX_VALUE)) |
| 69 | BUG("total_out mismatch"); |
| 70 | /* |
| 71 | * zlib does not update total_in when it returns Z_NEED_DICT, |
| 72 | * causing a mismatch here. Skip the sanity check in that case. |
| 73 | */ |
| 74 | if (status != Z_NEED_DICT && |
| 75 | (s->z.total_in & ULONG_MAX_VALUE) != |
| 76 | ((zlib_uLong_cap(s->total_in) + bytes_consumed) & ULONG_MAX_VALUE)) |
| 77 | BUG("total_in mismatch"); |
| 78 | |
| 79 | s->total_out += bytes_produced; |
| 80 | s->total_in += bytes_consumed; |
| 81 | /* zlib-ng marks `next_in` as `const`, so we have to cast it away. */ |
| 82 | s->next_in = (unsigned char *) s->z.next_in; |
| 83 | s->next_out = s->z.next_out; |
| 84 | s->avail_in -= bytes_consumed; |
| 85 | s->avail_out -= bytes_produced; |
| 86 | } |
| 87 | |
| 88 | void git_inflate_init(git_zstream *strm) |
| 89 | { |
no test coverage detected