在某些情况下,zLib膨胀具有空结果 [英] zLib inflate has empty result in some cases

查看:121
本文介绍了在某些情况下,zLib膨胀具有空结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序处理PDF文件并从中读取一些流.那里也有FlateEncoded流.我使用zlib的"inflate()"方法将其解压缩.

My program processes PDF files and reads some streams out of them. There are also FlateEncoded streams in there. I use the "inflate()" method of zlib to decompress them.

这通常可以很好地与以下代码配合使用:

This usually works really well with the following code:

static string FlateDecode(string s){

    int factor = 50;
    z_stream stream;
    while(true){
        char * out = new char[s.length()*factor];           

        stream.zalloc = Z_NULL;
        stream.zfree = Z_NULL;
        stream.opaque = Z_NULL;
        stream.avail_in = s.length();
        stream.next_in = (Bytef*)s.c_str();
        stream.avail_out = s.length()*factor;
        stream.next_out = (Bytef*)out;
        inflateInit(&stream);
        inflate(&stream, Z_FINISH);
        inflateEnd(&stream);


        if(stream.total_out >= factor*s.length()){
            delete[] out;
            factor *= 2;
            continue;

        }
        string result;
        for(unsigned long i = 0; i < stream.total_out; i++){
            result += out[i];
        }

        delete[] out;
        return result;
    }
}

但是对于某些流来说,膨胀会导致结果为空.它并不常见,但是确实会发生.有人知道为什么吗?

But inflate has an empty result for some streams. It´s not often, but it happens. Has someone an idea why?

因为所有PDF阅读器都能正确阅读PDF文件,所以流必须正常.

The streams must be ok because all PDF readers read the PDF files correctly.

感谢您的帮助!

更新

我已经上传了PDF和流,因此您可以自己检查它.

I've uploaded the PDF and the stream so you can check it by your own.

PDF ->流从字节43296开始

PDF -> The stream starts at byte 43296

更新2

我将无法解压缩的流与可以解压缩的流进行了比较.我注意到了一件有趣的事情:所有工作流都以2个字节的H%开头.有问题的流以ö>开头.现在有人吗?

I compared the streams that can´t be decompressed with the streams that can be decompressed. I've noticed an interesting thing: The working streams all begin with the 2 bytes H%. The problematic streams begin with ö>. Does anyone now what this means?

感谢您的帮助!

推荐答案

zlib似乎并不支持PDF文件中的所有压缩流.

zlib simply seems to not support all deflated streams found in PDF files.

这篇关于在某些情况下,zLib膨胀具有空结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆