3.1.5.3 Decompressing the Chained Message
If IsCompressionSupported is FALSE, Connection.SupportsChainedCompression is FALSE, or Connection.CompressionIds is empty, the receiver MUST skip the processing in this section.
The receiver MUST initialize RemainingCompressedDataSize with the size of the received compressed data and DecompressedMessage with empty buffer.
The compressed data MUST be decompressed as follows:
The first 8 bytes of the data MUST be interpreted as SMB2_COMPRESSION_CHAINED_PAYLOAD_HEADER, specified in section 2.2.42.2.1.
If CompressionAlgorithm in SMB2_COMPRESSION_CHAINED_PAYLOAD_HEADER is not one of the values specified in section 2.2.3.1.3, the connection MUST be disconnected as specified in section 3.2.7.1 or 3.3.7.1.
If CompressionAlgorithm in SMB2_COMPRESSION_CHAINED_PAYLOAD_HEADER is NONE:
If Length is greater than (the size of the received compressed message – 8) or OriginalCompressedSegmentSize in SMB2 COMPRESSION_TRANSFORM_HEADER, the connection MUST be disconnected as specified in section 3.2.7.1 or 3.3.7.1.
Length number of bytes following SMB2_COMPRESSION_CHAINED_PAYLOAD_HEADER MUST be interpreted as uncompressed data and MUST be appended to DecompressedMessage.
Otherwise, the data MUST be decompressed as follows:
If CompressionAlgorithm is Pattern_V1, the next 8 bytes MUST be interpreted as SMB2_COMPRESSION_PATTERN_PAYLOAD_V1, specified in section 2.2.42.2.2.
If Repetitions in SMB2_COMPRESSION_PATTERN_PAYLOAD_V1 is greater than OriginalCompressedSegmentSize in SMB2_COMPRESSION_TRANSFORM_HEADER_CHAINED, the connection MUST be disconnected as specified in section 3.2.7.1 or 3.3.7.1.
Otherwise, DecompressedMessage MUST be appended with Repetitions number of bytes initialized with the character specified in Pattern field.
Otherwise, the data of size specified in Length field minus size of OriginalPayloadSize field MUST be decompressed using the algorithm specified in CompressionAlgorithm field. If the size of the decompressed data is not equal to OriginalPayloadSize, the connection MUST be disconnected as specified in section 3.2.7.1 or section 3.3.7.1. DecompressedMessage MUST be appended with the decompressed data.
RemainingCompressedDataSize MUST be decremented by the size in Length field.
If the size of RemainingCompressedDataSize is greater than the size of SMB2_COMPRESSION_CHAINED_PAYLOAD_HEADER, the receiver MUST repeat step 2.
DecompressedMessage MUST be returned.