ZLIB compression Library bug ??
I'm using the ZLIB compression library for my Windows-based app. At the moment Im just trying to get the library to work properly before integration. Currently the problem is with the COMPRESSION2() wrapper. I set the 'level compression' value to 0 (no compression) expecting the input to be simply copied from src to destination unchanged however what actually happens is the resulting destination file is exactly 22 bytes larger than the source. WHats going on? Here's my code:
---
// ZLIB.cpp : Defines the entry point for the console application.
#include "zlib.h"
#include <fstream>
int main(int argc, char *argv[])
{
char *des, *src;
unsigned long desLen, srcLen;
std::ifstream inp("d:\\Test20.exe",std::ios::binary);
std::ofstream oup("d:\\Test20.zip",std::ios::binary);
if (!inp)
{std::cout << "Input error"; return 0;}
srcLen=3000;
desLen=srcLen*1.001+13;
src=new char[srcLen];
des=new char[desLen];
inp.read(src,srcLen);
while(inp.gcount())
{
compress2((Bytef *) des,&desLen,(Bytef *)src,inp.gcount(),0);
oup.write(des,desLen);
desLen=srcLen;
inp.read(src,srcLen);
}
oup.close();
inp.close();
return 0;
}
---
LIBZ.LIB and ZLIB.DLL were scavanged from another drawer to help with compiling but dont suspect them of being damaged.
Using a hex editor I found the output file to be littered with the extra 22 bytes in arbitrary locations. Some cases it just added data and in some cases it wrote inaccurate data.