c - 在 zlib 上为 gzip 读取错误时访问冲突
问题描述
我正在尝试使用 zlib 解压缩 c 中的二进制缓冲区
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;
}
我在使用随机地址读取时遇到访问冲突另外我正在使用 .NET 中的“GZipStream”来压缩缓冲区并使用 C 解压缩它
原始代码: https ://windrealm.org/tutorials/decompress-gzip-stream.php
解决方案
事实证明,在 Windows 的 Visual Studio 上编译 zlib 时使用“ReleaseWithoutAsm”而不是“Release”,因为inflate_fast()
asm 中的错误
推荐阅读
- javascript - 递减计数器有奇怪的行为
- php - 如何在 PHP 中获取一年中某一天的日期?
- r - 绘制 r 中的条件分布
- angular - 如何以角度反应形式清除 FormArray 值?
- java - 运行带有 txt 测试用例条目的 .py 并将输出重定向到另一个 .txt
- flutter - _$CustomClass 显示“返回类型“Type”不是“CustomClass”的错误,由匿名闭包定义。`
- javascript -
我应该使用
<a href="url">Something/>
因此,当我单击它时,它会将我重定向到我的 URL。
但现在我想对 onClick 方法做同样的事情(使用我的路由器)。
在我的代码中,我尝试使用它:
- java - 如何在 RSA 中进行密钥交换以进行解密
- java - 我如何让我的世界玩家看一个块
- c - 如何将位填充到 C 中的字符串?