/* not used even though it's defined ... */
int Sg_InflateReset(SgZStream *strm, int windowBits)
{
  int r;
#ifdef HAVE_ZLIB_INFLATE_RESET2
  if (windowBits < 0) {
    r = inflateReset(strm->strm);
  } else {
    r = inflateReset2(strm->strm, windowBits);
  }
#else
  /* to avoid not to use platform zlib */
  r = inflateReset(strm->strm);
#endif
  return r;
}
Beispiel #2
0
CpaStatus inflate_decompress(z_stream *stream,
        const Cpa8U *src, Cpa32U slen, Cpa8U *dst, Cpa32U dlen,
        CpaDcSessionState sessState)
{
#ifdef USE_ZLIB
    int ret = 0;
    int flushFlag = Z_NO_FLUSH;

    if(sessState == CPA_DC_STATELESS)
    {
        flushFlag = Z_SYNC_FLUSH/*Z_FINISH*/;
# if ZLIB_VERNUM >= 0x1234
        ret = inflateReset2(stream,-DEFLATE_DEF_WINBITS);
#else
        ret = inflateReset(stream);
#endif
        if(ret != Z_OK)
        {
            PRINT_ERR("Error in inflateReset\n");
            return CPA_STATUS_FAIL;
        }
    }


    stream->next_in = (Cpa8U *)src;
    stream->avail_in = slen;
    stream->next_out = (Cpa8U *)dst;
    stream->avail_out = dlen;

    ret = inflate(stream, flushFlag);
    if(ret < Z_OK)
    {
        PRINT_ERR("Error in inflate, ret = %d\n", ret);
        PRINT_ERR("stream->msg = %s\n", stream->msg);
        PRINT_ERR("stream->adler = %u\n", (unsigned int)stream->adler);
        return CPA_STATUS_FAIL;
    }
#endif
    return CPA_STATUS_SUCCESS;
}
Beispiel #3
0
CpaStatus inflate_init(z_stream *stream, CpaDcSessionState sessState)
{
#ifdef USE_ZLIB
    int ret = 0;
    stream->zalloc = (alloc_func)0;
    stream->zfree = (free_func)0;
    stream->opaque = (voidpf)0;
    stream->next_in = Z_NULL;
    stream->next_out = Z_NULL;
    stream->avail_in = stream->avail_out = stream->total_out = 0;
    stream->adler = 0;


    //ret = inflateInit(stream);
    ret = inflateInit2(stream, -DEFLATE_DEF_WINBITS);
    if(ret != Z_OK)
    {
        PRINT_ERR("Error in inflateInit2, ret = %d\n", ret);
        return CPA_STATUS_FAIL;
    }
    if(sessState == CPA_DC_STATEFUL)
    {
# if ZLIB_VERNUM >= 0x1234
        ret = inflateReset2(stream,-DEFLATE_DEF_WINBITS);
#else
        ret = inflateReset(stream);
#endif
        if(ret != Z_OK)
        {
            PRINT_ERR("Error in inflateReset\n");
            return CPA_STATUS_FAIL;
        }
    }
#endif
    return CPA_STATUS_SUCCESS;

}
Beispiel #4
0
/* 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 expected to return Z_STREAM_END).  If win is 47, then
   header information is collected with inflateGetHeader().  If a zlib stream
   is looking for a dictionary, then an empty dictionary is provided.
   inflate() is run until all of the input data is consumed. */
local void inf(char *hex, char *what, unsigned step, int win, unsigned len,
               int err)
{
    int ret;
    unsigned have;
    unsigned char *in, *out;
    z_stream strm, copy;
    gz_header head;

    mem_setup(&strm);
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit2(&strm, win);
    if (ret != Z_OK) {
        mem_done(&strm, what);
        return;
    }
    out = malloc(len);                          assert(out != NULL);
    if (win == 47) {
        head.extra = out;
        head.extra_max = len;
        head.name = out;
        head.name_max = len;
        head.comment = out;
        head.comm_max = len;
        ret = inflateGetHeader(&strm, &head);   assert(ret == Z_OK);
    }
    in = h2b(hex, &have);                       assert(in != NULL);
    if (step == 0 || step > have)
        step = have;
    strm.avail_in = step;
    have -= step;
    strm.next_in = in;
    do {
        strm.avail_out = len;
        strm.next_out = out;
        ret = inflate(&strm, Z_NO_FLUSH);       assert(err == 9 || ret == err);
        if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_NEED_DICT)
            break;
        if (ret == Z_NEED_DICT) {
            ret = inflateSetDictionary(&strm, in, 1);
                                                assert(ret == Z_DATA_ERROR);
            mem_limit(&strm, 1);
            ret = inflateSetDictionary(&strm, out, 0);
                                                assert(ret == Z_MEM_ERROR);
            mem_limit(&strm, 0);
            ((struct inflate_state *)strm.state)->mode = DICT;
            ret = inflateSetDictionary(&strm, out, 0);
                                                assert(ret == Z_OK);
            ret = inflate(&strm, Z_NO_FLUSH);   assert(ret == Z_BUF_ERROR);
        }
        ret = inflateCopy(&copy, &strm);        assert(ret == Z_OK);
        ret = inflateEnd(&copy);                assert(ret == Z_OK);
        err = 9;                        /* don't care next time around */
        have += strm.avail_in;
        strm.avail_in = step > have ? have : step;
        have -= strm.avail_in;
    } while (strm.avail_in);
    free(in);
    free(out);
    ret = inflateReset2(&strm, -8);             assert(ret == Z_OK);
    ret = inflateEnd(&strm);                    assert(ret == Z_OK);
    mem_done(&strm, what);
}
Beispiel #5
0
int
inflateMember (z_stream *z, FILE *f, size_t max_in, size_t max_out, void (*procMember) (z_stream *, int, void *), void *userPtr)
{
  /* Status returned by zlib functions. */
  int ret = Z_STREAM_END;

  Bytef *next_in = z->next_in, *next_out = z->next_out;

  int chunk = CHUNK_FIRST;

  /* Read chunks from file and inflate until end of stream or end of
   * file. */
  do
    {
      z->next_in = next_in;

      /* avail_in = number of bytes available at next_in. */
      z->avail_in = fread (z->next_in, 1, max_in, f);

      if (ferror (f))
        {
          (void) inflateEnd (z);
          return Z_ERRNO;
        }

      if (z->avail_in == 0)
        {
          break;
        }

      do
        {
          z->avail_out = max_out;

          ret = inflate (z, Z_NO_FLUSH);

          switch (ret)
            {
            case Z_NEED_DICT:
              ret = Z_DATA_ERROR;
              return ret;
            case Z_DATA_ERROR:
              return ret;
            case Z_MEM_ERROR:
              (void) inflateEnd (z);
              return ret;
            }

          z->next_out = next_out;

          if (procMember == NULL)
            {
              continue;
            }

          if (z->avail_out != 0 && ret == Z_STREAM_END)
            {
              if (chunk == CHUNK_FIRST)
                {
                  chunk = CHUNK_FIRST_LAST;
                }
              else if (chunk == CHUNK_MIDDLE)
                {
                  chunk = CHUNK_LAST;
                }
            }

          procMember (z, chunk, userPtr);

          chunk = CHUNK_MIDDLE;
        }
      while (z->avail_out == 0 && ret != Z_STREAM_END);
    }
  while (ret != Z_STREAM_END);

  if (z->avail_in)
    {
      fseek (f, -1 * (int) z->avail_in, SEEK_CUR);
    }

  z->next_in = next_in;
  z->next_out = next_out;

  ret = inflateReset2 (z, 31);

  return ret;
}