sync: accept TDLib zlib gzip_packed payloads
This commit is contained in:
parent
837535f375
commit
9106877123
3 changed files with 137 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ package mtprotoedge
|
|||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"compress/zlib"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
|
|
@ -413,7 +414,7 @@ func (s *Server) decodeGZIPWithGlobalBudgetLimit(b *bin.Buffer, limit int) ([]by
|
|||
}
|
||||
}
|
||||
|
||||
r, err := gzip.NewReader(bytes.NewReader(compressed))
|
||||
r, err := newGZIPPackedReader(compressed)
|
||||
if err != nil {
|
||||
release()
|
||||
return nil, func() {}, err
|
||||
|
|
@ -442,6 +443,19 @@ func (s *Server) decodeGZIPWithGlobalBudgetLimit(b *bin.Buffer, limit int) ([]by
|
|||
return data, release, nil
|
||||
}
|
||||
|
||||
// newGZIPPackedReader accepts the two wrapped DEFLATE formats emitted by
|
||||
// official Telegram clients. TDLib uses a zlib wrapper while DrKLO/gotd use a
|
||||
// gzip wrapper; raw DEFLATE is deliberately unsupported. Selecting by the gzip
|
||||
// magic keeps malformed gzip input on the gzip validator instead of silently
|
||||
// retrying it as another format.
|
||||
func newGZIPPackedReader(compressed []byte) (io.ReadCloser, error) {
|
||||
source := bytes.NewReader(compressed)
|
||||
if len(compressed) >= 2 && compressed[0] == 0x1f && compressed[1] == 0x8b {
|
||||
return gzip.NewReader(source)
|
||||
}
|
||||
return zlib.NewReader(source)
|
||||
}
|
||||
|
||||
// gzipPackedBytesView parses the TL bytes envelope without copying the compressed
|
||||
// payload. proto.GZIP.Decode calls bin.Buffer.Bytes, which duplicates the compressed
|
||||
// frame before allocating the decompressed result.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue