質問

This a question specific to the DEFLATE algorithm, but relates to gzip and zlib.

Suppose I have a gzip file that I know has several flush points in the file. Some of which are made with Z_SYNC_FLUSH and other Z_FULL_FLUSH. If I scan through the file, I can find all the flush points because they immediately follow a pattern of 0000ffff.

I know that I can resume decompression at a Z_FULL_FLUSH points because all the information needed to decompress is available (IE: The dictionary is reset). However, if I try to decompress from a Z_SYNC_FLUSH, I usually get a "zlib.error: Error -3 while decompressing: invalid distance too far back" error.

The question is this: If I try to decompress from a Z_SYNC_FLUSH point, am I guaranteed to either:

  1. Properly decompress that block and subsequent blocks
  2. Fail with "distance too far" error

In other words, am I guaranteed that I will never silently decompress with bad data (I'm not talking about the CRC32 check at the end of the gzip, but whether zlib will loudly complain)?

Assumptions:

  1. Assume that I am able to identify flush points perfectly. Let's pretend that I don't mis-identify random bits as the sync marker nor that the pattern so happens to appear in a type 0 block. This is unrealistic, but just assume it's true.
  2. Assume the file is never corrupted and is always a legitimate gzip file.
役に立ちましたか?

解決

If a Z_SYNC_FLUSH results in a subsequent stream that does not give a distance-too-far error, then it is, by accident, equivalent to and indistinguishable from a Z_FULL_FLUSH.

I would not expect this to happen very often.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top