Я пытаюсь распаковать двоичный буфер в c, используя zlib
BOOL gzipInflate(char* lpFileIn, DWORD lpFileInSize) {
z_stream strm;
char* uncomp, * uncomp2;
unsigned int uncompLength, half_length;
int err;
bool done = false;
uncompLength = lpFileInSize;
half_length = lpFileInSize / 2;
uncomp = (char*)calloc(sizeof(char), uncompLength);
memset(&strm, 0, sizeof(strm));
strm.next_in = (Bytef*)lpFileIn;
strm.avail_in = (uInt)lpFileInSize;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.total_out = Z_NULL;
if (inflateInit2(&strm, 16 + MAX_WBITS) != Z_OK) {
free(uncomp);
return FALSE;
}
while (!done)
{
if (strm.total_out >= uncompLength) {
uncomp2 = (char*)calloc(sizeof(char), uncompLength + half_length);
memcpy(uncomp2, uncomp, uncompLength);
uncompLength += half_length;
free(uncomp);
uncomp = uncomp2;
}
strm.next_out = (Bytef*)(uncomp + strm.total_out);
strm.avail_out = uncompLength - strm.total_out;
err = inflate(&strm, Z_SYNC_FLUSH);
if (err == Z_STREAM_END) {
done = true;
}
else if (err != Z_OK) {
break;
}
}
if (inflateEnd(&strm) != Z_OK) {
free(uncomp);
return FALSE;
}
free(uncomp);
return TRUE;
}
Я получаю нарушение прав доступа при чтении со случайным адресом. Также я использую GZipStream из. NET для сжатия буфер и распаковка его с помощью C
Оригинальный код: https://windrealm.org/tutorials/decompress-gzip-stream.php