Beispiel #1
0
static TACommandVerdict inflateInit__cmd(TAThread thread,TAInputStream stream)
{
    z_stream strm;
    int stream_size, res, is_null;
    char* version;

    is_null = readZStream(&stream, &strm);
    version = readString(&stream);
    stream_size = readInt(&stream);

    START_TARGET_OPERATION(thread);

    if(!is_null)
        res = inflateInit_(&strm, version, stream_size);
    else
        res = inflateInit_(0, version, stream_size);

    END_TARGET_OPERATION(thread);

    ta_debug_printf("res==%d\n");

    // Response
    if(!is_null)
        writeZStream(thread, &strm);
    else
        writeZStream(thread, 0);

    writeInt(thread, res);

    sendResponse(thread);

    return taDefaultVerdict;
}
Beispiel #2
0
int XinflateInit_(Z1Ctx *Zc,const char *version,int siz){
	Z32_stream Z32;

	if( inflateInit_(Zc->z1_Z1,version,sizeof(Z64_stream)) == Z_OK ){
		Zc->z1_ssize = sizeof(Z64_stream);
		return Z_OK;
	}
	Zenpack(Zc,&Z32);
	if( inflateInit_(&Z32,version,sizeof(Z32_stream)) == Z_OK ){
		Zdepack(Zc,&Z32);
		Zc->z1_ssize = sizeof(Z32_stream);
		return Z_OK;
	}
	return Z_VERSION_ERROR;
}
Beispiel #3
0
static int zz_uncompress(Bytef *dest, uLongf * destLen, const Bytef *source,
                         uLong sourceLen)
{
    z_stream stream;
    int err;

    stream.next_in = (Bytef *)source;
    stream.avail_in = (uInt) sourceLen;
    /* Check for source > 64K on 16-bit machine: */
    if ((uLong) stream.avail_in != sourceLen)
        return Z_BUF_ERROR;

    stream.next_out = dest;
    stream.avail_out = (uInt) * destLen;
    if ((uLong) stream.avail_out != *destLen)
        return Z_BUF_ERROR;

    stream.zalloc = (alloc_func) 0;
    stream.zfree = (free_func) 0;

    err = inflateInit_(&stream, ZLIB_VERSION, sizeof(z_stream));
    if (err != Z_OK)
        return err;

    err = inflate(&stream, Z_FINISH);
    if (err != Z_STREAM_END) {
        inflateEnd(&stream);
        return err;
    }
    *destLen = stream.total_out;

    err = inflateEnd(&stream);
    return err;
}
Beispiel #4
0
static int zlib_stateful_init(COMP_CTX *ctx)
{
    int err;
    struct zlib_state *state = OPENSSL_zalloc(sizeof(*state));

    if (state == NULL)
        goto err;

    state->istream.zalloc = zlib_zalloc;
    state->istream.zfree = zlib_zfree;
    state->istream.opaque = Z_NULL;
    state->istream.next_in = Z_NULL;
    state->istream.next_out = Z_NULL;
    err = inflateInit_(&state->istream, ZLIB_VERSION, sizeof(z_stream));
    if (err != Z_OK)
        goto err;

    state->ostream.zalloc = zlib_zalloc;
    state->ostream.zfree = zlib_zfree;
    state->ostream.opaque = Z_NULL;
    state->ostream.next_in = Z_NULL;
    state->ostream.next_out = Z_NULL;
    err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION,
                       ZLIB_VERSION, sizeof(z_stream));
    if (err != Z_OK)
        goto err;

    ctx->data = state;
    return 1;
 err:
    OPENSSL_free(state);
    return 0;
}
Beispiel #5
0
static int zlib_stateful_init(COMP_CTX *ctx)
{
    int err;
    struct zlib_state *state =
        (struct zlib_state *)OPENSSL_malloc(sizeof(struct zlib_state));

    if (state == NULL)
        goto err;

    state->istream.zalloc = zlib_zalloc;
    state->istream.zfree = zlib_zfree;
    state->istream.opaque = Z_NULL;
    state->istream.next_in = Z_NULL;
    state->istream.next_out = Z_NULL;
    state->istream.avail_in = 0;
    state->istream.avail_out = 0;
    err = inflateInit_(&state->istream, ZLIB_VERSION, sizeof(z_stream));
    if (err != Z_OK)
        goto err;

    state->ostream.zalloc = zlib_zalloc;
    state->ostream.zfree = zlib_zfree;
    state->ostream.opaque = Z_NULL;
    state->ostream.next_in = Z_NULL;
    state->ostream.next_out = Z_NULL;
    state->ostream.avail_in = 0;
    state->ostream.avail_out = 0;
    err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION,
                       ZLIB_VERSION, sizeof(z_stream));
    if (err != Z_OK)
        goto err;

    CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
    CRYPTO_set_ex_data(&ctx->ex_data, zlib_stateful_ex_idx, state);
    return 1;
 err:
    if (state)
        OPENSSL_free(state);
    return 0;
}
Beispiel #6
0
/* cover all of the lines in inflate.c up to inflate() */
local void cover_support(void)
{
    int ret;
    z_stream strm;

    mem_setup(&strm);
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit(&strm);                   assert(ret == Z_OK);
    mem_used(&strm, "inflate init");
    ret = inflatePrime(&strm, 5, 31);           assert(ret == Z_OK);
    ret = inflatePrime(&strm, -1, 0);           assert(ret == Z_OK);
    ret = inflateSetDictionary(&strm, Z_NULL, 0);
                                                assert(ret == Z_STREAM_ERROR);
    ret = inflateEnd(&strm);                    assert(ret == Z_OK);
    mem_done(&strm, "prime");

    inf("63 0", "force window allocation", 0, -15, 1, Z_OK);
    inf("63 18 5", "force window replacement", 0, -8, 259, Z_OK);
    inf("63 18 68 30 d0 0 0", "force split window update", 4, -8, 259, Z_OK);
    inf("3 0", "use fixed blocks", 0, -15, 1, Z_STREAM_END);
    inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR);

    mem_setup(&strm);
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream));
                                                assert(ret == Z_VERSION_ERROR);
    mem_done(&strm, "wrong version");

    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit(&strm);                   assert(ret == Z_OK);
    ret = inflateEnd(&strm);                    assert(ret == Z_OK);
    fputs("inflate built-in memory routines\n", stderr);
}
Beispiel #7
0
void Extension::DecompressReceivedBinary()
{
    if (ThreadData.ReceivedMsg.Size <= 0)
        CreateError("Cannot decompress; Message is too small.");
    else
    {
        int ret;
        z_stream strm = { 0 };
        ret = inflateInit_(&strm, ZLIB_VERSION, sizeof(z_stream));
        if (ret)
        {
            std::stringstream error;
            error << "Error " << ret << "occured with initiating decompression.";
            CreateError(error.str().c_str());
            return;
        }

        unsigned char * output_buffer = NULL, *output_buffer_pointer = NULL;
        strm.next_in = (unsigned char *)ThreadData.ReceivedMsg.Content;
        strm.avail_in = ThreadData.ReceivedMsg.Size;
        // run inflate() on input until output buffer not full, finish
        // compression if all of source has been read in
        do {
            // Allocate memory for compression
            output_buffer_pointer = (unsigned char *)realloc(output_buffer, (output_buffer ? _msize(output_buffer) : 0) + 1024);
            if (!output_buffer_pointer)
            {
                std::stringstream error;
                error << "Error, could not allocate enough memory. Desired " << (output_buffer ? _msize(output_buffer) : 0) + 1024 << "bytes.";
                if (output_buffer)
                    free(output_buffer);

                CreateError(error.str().c_str());
                inflateEnd(&strm);
                return;
            }

            output_buffer = output_buffer_pointer;
            output_buffer_pointer += _msize(output_buffer) - 1024;
            strm.avail_out = 1024;
            strm.next_out = output_buffer_pointer;
            ret = inflate(&strm, Z_FINISH);
            if (ret < Z_OK)
            {
                std::stringstream error;
                error << "Error with decompression, inflate() returned " << ret << "! Text: " << strm.msg ? strm.msg : "";
                free(output_buffer);
                CreateError(error.str().c_str());
                inflateEnd(&strm);
                return;
            }

        } while (strm.avail_in != 0);

        if (ret < 0)
        {
            std::stringstream error;
            error << "Error with decompression: " << ret << "! Text: " << strm.msg ? strm.msg : "";
            CreateError(error.str().c_str());
            inflateEnd(&strm);
            return;
        }
        inflateEnd(&strm);
        char * ThisMsg = ThreadData.ReceivedMsg.Content;
        free(ThreadData.ReceivedMsg.Content);
        ThreadData.ReceivedMsg.Content = (char *)output_buffer;
        ThreadData.ReceivedMsg.Cursor = 0;
        ThreadData.ReceivedMsg.Size = _msize(output_buffer);
        for (std::vector<SaveExtInfo *>::iterator i = Saved.begin(); i != Saved.end(); ++i)
        {
            if (ThisMsg != (*i)->ReceivedMsg.Content)
                break;
            (*i)->ReceivedMsg.Content = (char *)output_buffer;
            (*i)->ReceivedMsg.Cursor = 0;
            (*i)->ReceivedMsg.Size = _msize(output_buffer);
        }
    }
}