英文:
Is there any way to know that gzip compressed byte[] has been compressed more than once in java?
问题
我正在使用io.netty.handler.codec.http.HttpContentDecompressor在我的Spring Boot应用程序服务器中解压gzip压缩的请求,它成功地进行了解压缩。但是,当客户端错误地发送了两次压缩的请求主体时,Netty的HttpContentDecompressor只能解压缩一次,请求主体仍然是压缩的。因此,我的下游应用程序开始失败,因为它们假设只会收到已解压缩的数据。是否有方法可以知道接收到的byte[]是否已完全压缩或仍然未解压缩?
英文:
I am using io.netty.handler.codec.http.HttpContentDecompressor to decompress the gzip compressed request in my spring boot application server and its decompressing it fine. However when client send me 2 times compressed request body(by mistake) then netty HttpContentDecompressor could decompress it only once and request body was still compressed. So my downstream application started getting failed as they had assumption that they will only get the decompressed data.
Is there any way to know that receiving byte[] has been fully compressed or still decompressed?
答案1
得分: 2
gzip
压缩文件包含众所周知的头部字节。
https://en.wikipedia.org/wiki/Gzip
> 一个包含魔术数字(1f 8b)、压缩方法(08代表DEFLATE)、1字节头部标志、4字节时间戳、压缩标志和操作系统ID的10字节头部。
在第一次解压缩后,请检查是否存在1f 8b
。
另外,如果您接受要处理的文件且文件类型很重要,最好验证受限文件集合。
英文:
gzip
ed files contain well-known header bytes
https://en.wikipedia.org/wiki/Gzip
> a 10-byte header, containing a magic number (1f 8b), the compression method (08 for DEFLATE), 1-byte of header flags, a 4-byte timestamp, compression flags and the operating system ID.
After your first decompression, check to see if 1f 8b
is present.
Aside, if you are accepting files for processing and the file type is important, it's good practice to validate the restricted sets of files.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论