generic inflate() run, where hex is the hexadecimal input data, what is the text to include in an error message, step is how much input data to feed inflate() on each call, or zero to feed it all, win is the window bits parameter to inflateInit2(), len is the size of the output buffer, and err is the error code expected from the first inflate() call (the second inflate() call is exp
| 282 | is looking for a dictionary, then an empty dictionary is provided. |
| 283 | inflate() is run until all of the input data is consumed. */ |
| 284 | local void inf(char *hex, char *what, unsigned step, int win, unsigned len, |
| 285 | int err) |
| 286 | { |
| 287 | int ret; |
| 288 | unsigned have; |
| 289 | unsigned char *in, *out; |
| 290 | z_stream strm, copy; |
| 291 | gz_header head; |
| 292 | |
| 293 | mem_setup(&strm); |
| 294 | strm.avail_in = 0; |
| 295 | strm.next_in = Z_NULL; |
| 296 | ret = inflateInit2(&strm, win); |
| 297 | if (ret != Z_OK) { |
| 298 | mem_done(&strm, what); |
| 299 | return; |
| 300 | } |
| 301 | out = malloc(len); assert(out != NULL); |
| 302 | if (win == 47) { |
| 303 | head.extra = out; |
| 304 | head.extra_max = len; |
| 305 | head.name = out; |
| 306 | head.name_max = len; |
| 307 | head.comment = out; |
| 308 | head.comm_max = len; |
| 309 | ret = inflateGetHeader(&strm, &head); assert(ret == Z_OK); |
| 310 | } |
| 311 | in = h2b(hex, &have); assert(in != NULL); |
| 312 | if (step == 0 || step > have) |
| 313 | step = have; |
| 314 | strm.avail_in = step; |
| 315 | have -= step; |
| 316 | strm.next_in = in; |
| 317 | do { |
| 318 | strm.avail_out = len; |
| 319 | strm.next_out = out; |
| 320 | ret = inflate(&strm, Z_NO_FLUSH); assert(err == 9 || ret == err); |
| 321 | if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_NEED_DICT) |
| 322 | break; |
| 323 | if (ret == Z_NEED_DICT) { |
| 324 | ret = inflateSetDictionary(&strm, in, 1); |
| 325 | assert(ret == Z_DATA_ERROR); |
| 326 | mem_limit(&strm, 1); |
| 327 | ret = inflateSetDictionary(&strm, out, 0); |
| 328 | assert(ret == Z_MEM_ERROR); |
| 329 | mem_limit(&strm, 0); |
| 330 | ((struct inflate_state *)strm.state)->mode = DICT; |
| 331 | ret = inflateSetDictionary(&strm, out, 0); |
| 332 | assert(ret == Z_OK); |
| 333 | ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_BUF_ERROR); |
| 334 | } |
| 335 | ret = inflateCopy(©, &strm); assert(ret == Z_OK); |
| 336 | ret = inflateEnd(©); assert(ret == Z_OK); |
| 337 | err = 9; /* don't care next time around */ |
| 338 | have += strm.avail_in; |
| 339 | strm.avail_in = step > have ? have : step; |
| 340 | have -= strm.avail_in; |
| 341 | } while (strm.avail_in); |
no test coverage detected