gpt4 book ai didi

c - zlib 中解压消息的问题

转载 作者:行者123 更新时间:2023-11-30 17:11:14 25 4
gpt4 key购买 nike

我遇到以下问题。我需要解压缩从这里生成的linux内核消息:https://lkml.org/lkml/2014/3/17/525

内核中消息的压缩如下所示:

static int __init qr_compr_init(void)
{
size_t size = max(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
zlib_inflate_workspacesize());
stream.workspace = vmalloc(size);
if (!stream.workspace)
return -ENOMEM;
return 0;
}

static void qr_compr_exit(void)
{
vfree(stream.workspace);
}

static int qr_compress(void *in, void *out, size_t inlen, size_t outlen)
{
int err, ret;
int i;
z_stream infstream;

ret = -EIO;

err = qr_compr_init();
if (err != 0)
goto error;
mutex_lock(&compr_mutex);
err = zlib_deflateInit(&stream, COMPR_LEVEL);
if (err != Z_OK)
goto error;

stream.avail_in = inlen;
stream.total_in = 0;
stream.next_out = out;
stream.avail_out = outlen;
stream.total_out = 0;

err = zlib_deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END)
goto error;

err = zlib_deflateEnd(&stream);
if (err != Z_OK)
goto error;

if (stream.total_out >= stream.total_in)
goto error;

ret = stream.total_out;

error:
mutex_unlock(&compr_mutex);
return ret;
}

它使用内核中的 zlib 库。

我的解压代码如下:

void uncompress_init()
{
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
stream.next_in = NULL;
stream.avail_in = 0;
}

int uncompress_block(void *dst, int dstlen, void *src, int srclen)
{
int err;

stream.next_in = src;
stream.avail_in = srclen;

stream.next_out = dst;
stream.avail_out = dstlen;

inflateInit(&stream);

err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END)
goto err;
return stream.total_out;

err:
printf("Error %d while decompressing!\n", err);
printf("%p(%d)->%p(%d)\n", src, srclen, dst, dstlen);
return -1;
}

void uncompress_exit()
{
inflateEnd(&stream);
}

不幸的是它不起作用。我收到以下错误消息:

compressed string size: 8
compressed string: x廳L#
Error -3 while decompressing!
0x7ffe9be69f68(8)->0x7ffe9be6a360(1024)
Uncompressed size is: 0
Uncompressed string is:

我在内核代码中找到了这个解压示例。我非常感谢您的帮助。

最佳答案

-3 是数据错误,表示为 inflate 提供了无效的 zlib 或 deflate 输入。因此,你输入的inflate 并不是deflate 的结果。沿线的某个地方,数据要么被损坏,要么被错误识别。

关于c - zlib 中解压消息的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32415992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com