0

I am struggling with decompression of a Zlib compressed Mime body of AS2 request coming from BizTalk Server.

The thing is:

The HTTP Body I receive looks as expected. I can read the ASCII encoded Mime Header:

"Content-type: application/pkcs7-mime; smime-type=compressed-data; name=smime.p7m\r\nContent-Transfer-Encoding: binary\r\n\r\n"

Ending with two line breaks, I am expecting the compressed body after. But when I use Ionic.Zlib ZlibStream.UncompressBuffer() to decompress the following bytes it throws an error.

Zlib Header can be identified for example by hex coded bytes "78da". When I start decompressing it from there on, it works fine.

What are the bytes between the two line breaks ending mime header and "78da" starting zlib compressed data?

"3080060b2a864886f70d0109100109a0803080020100300f060b2a864886f70d01091003080500308006092a864886f70d010701a080248004820769"

Next problem, if I read all bytes to the end, the last bytes can not be decompressed. AS far as I Understood the zLib data should end with adler32 checksum, but how can I identify the end or length of the compressed data without trying to decompress. I see some trailing bytes after the sucessfully decompressed data: "1f9b1f1fcbc51f0482000445a59371" What is that?

Thanks for your ideas!

Trombone
  • 1
  • 1

1 Answers1

0

You cannot find the end of the compressed data without decompressing. You don't need to save the result of the decompression, but you at least need to decode all of the compressed data in order to find where it self terminates.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • Hi Mark,thanks for the quick answer, took me 1 year and 9 month to continue on this...:) By "decode all of the compressed data in order to find where it self terminates" you mean inflating it in chunks/buffer? how do I know the buffer size for the inflate? If I understood correct it works like using Ionic.Zlib.ZlibStream.UncompressBuffer(compressedBuffer); in a loop and when it fails it probably is the end? but what if the end of the last successfully inflated buffer does not match with the end of the compressed data? – Trombone Feb 24 '23 at 23:10
  • Yes, inflating in chunks. With zlib's `inflate()`, you can use any buffer size you like. It doesn't "fail" (unless the input is invalid). It tells you when the compressed data ended. Any input data that follows the compressed data is left in the `inflate()` input buffer, unconsumed. – Mark Adler Feb 25 '23 at 03:13