Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:50:56+00:00 2026-06-09T13:50:56+00:00

Hi everyone I am basically trying to use the zlib library, but I am

  • 0

Hi everyone I am basically trying to use the zlib library, but I am having troubles when I try to inflate a self-deflated file , although when I inflate other zlib´d files it works fine.

The compressing code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char BYTE;
typedef unsigned int  UINT; 
#include "zlib.h"
#define HEADERSIZE (1024)
#define CHUNKSIZE 4096
#define SWAPINT(x) (((x)&0xFF) << 24)|(((x)&0xFF00) << 8) | (((x)&0xFF0000) >> 8) | (((x)&0xFF000000) >> 24)
#define DEFLATESIZE 65536
const char *mz_error(int err)
{
  static struct { int m_err; const char *m_pDesc; } s_error_descs[] =
  {
    { Z_OK, "" }, { Z_STREAM_END, "stream end" }, { Z_NEED_DICT, "need dictionary" }, { Z_ERRNO, "file error" }, { Z_STREAM_ERROR, "stream error" },
    { Z_DATA_ERROR, "data error" }, { Z_MEM_ERROR, "out of memory" }, { Z_BUF_ERROR, "buf error" }, { Z_VERSION_ERROR, "version error" }
  };
  UINT i; for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i) if (s_error_descs[i].m_err == err) return s_error_descs[i].m_pDesc;
  return NULL;
}

char* myinflate(char* buffer, int bufsize, int* inflatedSize)
{
    BYTE tmpinf[DEFLATESIZE];
    char* inflated=(char*)malloc(DEFLATESIZE);
    int ret,have;
    z_stream strm;
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    strm.avail_in = bufsize;
    strm.next_in = (Bytef*)buffer;
    strm.avail_out = sizeof(tmpinf);
    strm.next_out = tmpinf;
    ret = inflateInit(&strm);
    printf("%s",mz_error(ret));
    ret = inflate(&strm, Z_FINISH);
    printf("%s",mz_error(ret));
    if(ret == Z_DATA_ERROR)
        printf(strm.msg);
    inflateEnd(&strm);
    have = strm.total_out;
    printf("%d\n",have);
    memcpy(inflated,tmpinf,have);
    *inflatedSize = have;
    return inflated;
}
char* mydeflate(char* buffer, int bufsize, int* deflatedSize)
{
    BYTE tmpdef[CHUNKSIZE*4];
    char* deflated=(char*)malloc(DEFLATESIZE);
    int have,ret;
    z_stream strm;
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    strm.avail_in = bufsize;
    strm.next_in = (Bytef*)buffer;
    strm.avail_out = sizeof(tmpdef);
    strm.next_out = tmpdef;
    ret = deflateInit(&strm,Z_DEFAULT_COMPRESSION);
    printf("%s",mz_error(ret));
    ret = deflate(&strm, Z_FINISH);
    printf("%s",mz_error(ret));
    ret = deflateEnd(&strm);
    printf("%s",mz_error(ret));
    have = strm.total_out;
    printf("%d\n",have);
    memcpy(deflated,tmpdef,have);
    *deflatedSize = have;
    return deflated;
}
int main()
{
    FILE* fptr = fopen("test.in","rb");
    fseek (fptr, 0, SEEK_END);
    int size  = ftell(fptr);
    fseek (fptr, 0, SEEK_SET);
    char* buffer = (char*)malloc(size);
    fread(buffer,1,size,fptr);
    int infsize,defsize;
    char* buf = myinflate(buffer,size,&infsize);
    FILE* out = fopen("testinf.hex","wb");
    fwrite(buf,1,infsize,out);
    fclose(out);
    char* buf2 = mydeflate(buf,infsize,&defsize);
    out  = fopen("testdef.hex","wb");
    fwrite(buf2,1,defsize,out);
    fclose(out);
    int buf3size;
    char* buf3 = myinflate(buf2,defsize,&buf3size);
    out  = fopen("testinfdef.hex","wb");
    fwrite(buf3,1,buf3size,out);
}

http://www.filehosting.org/file/details/364574/eEyzAbMuCp93MmGk/test.in

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:50:58+00:00Added an answer on June 9, 2026 at 1:50 pm

    You’re not checking any return codes. How could you possibly expect to know what’s going on? Check the return codes from all functions that can return errors!

    There may simply not be enough space provided for compression and/or decompression. The return codes from inflate() and compress() indicate whether that is the case or not.

    By the way, you malloc() inflated twice, overwriting the first one resulting in a massive memory leak.

    Also you blithely convert an int pointer to an unsigned long pointer. If they have different lengths, then you will have a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi everyone I am having a problem trying to get this to work. Basically
(source: flickr.com ) Hi again everyone :) So today I'm trying to basically create
Basically, I am trying to work on the front end of a website, but
Hey everyone, I'm basically new to programming. I've decided to try and get started
Hey everyone, I am having a problem with a website I'm trying to build;
Basically everyone writing about member enumeration in JavaScript heavily advocates the use of the
Ok, so i'm basically trying to load the contents of a .txt file that
Good afternoon everyone So, I'm trying to dynamically change textview's properties. basically, I defined
I'm basically trying to follow what everyone else is saying ( http://hc.apache.org/httpclient-3.x/tutorial.html ) to
Everyone, every blog is talking about HTML 5 and giving solution to use HTML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.