| 4406 | } |
| 4407 | |
| 4408 | static int stbi__parse_uncompressed_block(stbi__zbuf *a) |
| 4409 | { |
| 4410 | stbi_uc header[4]; |
| 4411 | int len,nlen,k; |
| 4412 | if (a->num_bits & 7) |
| 4413 | stbi__zreceive(a, a->num_bits & 7); // discard |
| 4414 | // drain the bit-packed data into header |
| 4415 | k = 0; |
| 4416 | while (a->num_bits > 0) { |
| 4417 | header[k++] = (stbi_uc) (a->code_buffer & 255); // suppress MSVC run-time check |
| 4418 | a->code_buffer >>= 8; |
| 4419 | a->num_bits -= 8; |
| 4420 | } |
| 4421 | if (a->num_bits < 0) return stbi__err("zlib corrupt","Corrupt PNG"); |
| 4422 | // now fill header the normal way |
| 4423 | while (k < 4) |
| 4424 | header[k++] = stbi__zget8(a); |
| 4425 | len = header[1] * 256 + header[0]; |
| 4426 | nlen = header[3] * 256 + header[2]; |
| 4427 | if (nlen != (len ^ 0xffff)) return stbi__err("zlib corrupt","Corrupt PNG"); |
| 4428 | if (a->zbuffer + len > a->zbuffer_end) return stbi__err("read past buffer","Corrupt PNG"); |
| 4429 | if (a->zout + len > a->zout_end) |
| 4430 | if (!stbi__zexpand(a, a->zout, len)) return 0; |
| 4431 | memcpy(a->zout, a->zbuffer, len); |
| 4432 | a->zbuffer += len; |
| 4433 | a->zout += len; |
| 4434 | return 1; |
| 4435 | } |
| 4436 | |
| 4437 | static int stbi__parse_zlib_header(stbi__zbuf *a) |
| 4438 | { |
no test coverage detected