Thread

Posted on Fri Mar 28 06:04:25 2008 by dpramanik
Uncompress returns -3
Here goes my code
This method reads the local header ZIPFILE * readZipData(FILE *fp) { struct ZIPFILE * pZip = NULL; int tempData; short int tempShortInt; struct ZipHeader *header = NULL; fseek(fp,-4,SEEK_CUR); int *filePos = (int*) malloc(sizeof(int)); *filePos = ftell(fp); header = (struct ZipHeader*)malloc(sizeof(struct ZipHeader)); fread(&tempData,sizeof(int),1,fp); header.localHeader = tempData; fread(&tempShortInt,sizeof(short int),1,fp); header-version = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-genPurposeFlag = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-compressionMethod = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-lastModFileTime = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-lastModFileDate = tempShortInt; fread(&tempData,sizeof(int),1,fp); header-crc = tempData; fread(&tempData,sizeof(int),1,fp); header-compressedSize = tempData; fread(&tempData,sizeof(int),1,fp); header-uncompressedSize = tempData; fread(&tempShortInt,sizeof(short int),1,fp); header-fileNameLength = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-extraFieldLength = tempShortInt; pZip = (struct ZIPFILE*) malloc(sizeof(struct ZIPFILE)); pZip-FileName = readFileName(header-fileNameLength,fp); pZip-Position = *filePos; pZip-Header = header; pZip-CompressRatio = (1-((float)header-compressedSize/(float)header-uncompressedSize)) * 100; pZip-FileData = readFileData(fp,header-compressedSize,header-extraFieldLength); if(header-genPurposeFlag & 0x4) fseek(fp,12,SEEK_CUR); return pZip; } This reads the compressed file data BYTE * readFileData(FILE *fp, int fileLength, int bytesToSkip) { BYTE * fileData = NULL; if(bytesToSkip 0) fseek(fp,bytesToSkip,SEEK_CUR); fileData = (BYTE *) calloc(fileLength,1); int index = 0; while(index != fileLength) { fileData[index++] = fgetc(fp); } // fread((BYTE*)fileData,fileLength,1,fp); return fileData; } I also read the centrla directory then when I try to call uncompress using unsigned long actualLen = pData-Header-uncompressedSize; BYTE *pActualData = NULL; pActualData = (BYTE*)malloc(pData-Header-uncompressedSize); pByteData points to the contents of compressed file int i = uncompress(pActualData,&actualLen,pByteData,compressedSize); When this is executed it returns -3 from inflate method basically it returns from this code inside +inflate method if ( #endif ((BITS(8) << 8) + (hold 8)) % 31) { strm-msg = (char *)"incorrect header check"; ----------------- +------------- state-mode = BAD; break; I hope this will give enough information whats goin wroing....Please let me know what i'm doing wro +ng
NOTE:: SYNTAX may be wrong as the editor didn't allowed pointer indirection character
Direct Responses: 7491 | Write a response
Posted on Fri Mar 28 11:08:53 2008 by pmarquess in response to 7490
Re: Uncompress returns -3
Although the has absolutely nothing to do with the Compress::Zlib perl module, I can guess what your problem is.

Assuming the uncompress function you are calling is the one supplied with the zlib library, then that cannot be used to if you are manipulating a zip file. The compress/uncompress functions supplied in zlib manipulate RFC 1950 data streams. For a zip file you need to work with RFC1951 data streams.

To do that you need to use the inflateInit2 and inflate functions supplied with zlib. To get inflateInit2 to work in RFC1951 mode, you need to set the windowBits parameter to -15 (i.e. minus 15).

Paul
Write a response