96 {
98 int ret;
99 unsigned have;
100 z_stream stream_data;
101 unsigned char* in = &((*src)[0]);
102 unsigned char* out = &((*dst)[0]);
103 unsigned int src_idx = 0;
104 unsigned int dst_idx = 0;
105
106
107 std::memset(&stream_data, 0, sizeof(z_stream));
108
109 ret = inflateInit(&stream_data);
110 if (ret != Z_OK) {
111 return ret;
112 }
113
114 do {
115 in = &((*src)[src_idx]);
118 } else {
119 stream_data.avail_in = static_cast<unsigned int>(src->size()) - src_idx;
120 }
121 stream_data.next_in = in;
122 src_idx += stream_data.avail_in;
123 if (stream_data.avail_in == 0) {
124 break;
125 }
126
127 do {
129 stream_data.next_out = out;
130 ret = inflate(&stream_data, Z_NO_FLUSH);
131 DCHECK_NE(ret, Z_STREAM_ERROR);
132 switch (ret) {
133 case Z_NEED_DICT:
134 ret = Z_DATA_ERROR;
135 case Z_DATA_ERROR:
136 case Z_MEM_ERROR:
137 (void)inflateEnd(&stream_data);
138 return ret;
139 }
141 dst_idx += have;
144 }
145 out = &((*dst)[dst_idx]);
146 } while (stream_data.avail_out == 0);
147
148
149 } while (ret != Z_STREAM_END);
150
151
152 (void)inflateEnd(&stream_data);
153 dst->resize(dst_idx);
154 return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
155}