| 31 | } |
| 32 | |
| 33 | size_t GzipInflator::Inflate (const uint8_t * in, size_t inLen, uint8_t * out, size_t outLen) |
| 34 | { |
| 35 | if (inLen < 23) return 0; |
| 36 | if (in[10] == 0x01) // non compressed |
| 37 | { |
| 38 | size_t len = bufle16toh (in + 11); |
| 39 | if (len + 23 < inLen) |
| 40 | { |
| 41 | LogPrint (eLogError, "Gzip: Incorrect length"); |
| 42 | return 0; |
| 43 | } |
| 44 | if (len > outLen) len = outLen; |
| 45 | memcpy (out, in + 15, len); |
| 46 | return len; |
| 47 | } |
| 48 | else |
| 49 | { |
| 50 | if (m_IsDirty) inflateReset (&m_Inflator); |
| 51 | m_IsDirty = true; |
| 52 | m_Inflator.next_in = const_cast<uint8_t *>(in); |
| 53 | m_Inflator.avail_in = inLen; |
| 54 | m_Inflator.next_out = out; |
| 55 | m_Inflator.avail_out = outLen; |
| 56 | int err; |
| 57 | if ((err = inflate (&m_Inflator, Z_NO_FLUSH)) == Z_STREAM_END) |
| 58 | return outLen - m_Inflator.avail_out; |
| 59 | // else |
| 60 | if (err) |
| 61 | LogPrint (eLogError, "Gzip: Inflate error ", err); |
| 62 | return 0; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void GzipInflator::Inflate (const uint8_t * in, size_t inLen, std::ostream& os) |
| 67 | { |
no test coverage detected