mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fixed gunzip
This commit is contained in:
parent
0894b6d48b
commit
7c37277430
@ -10,8 +10,8 @@ FOUNDATION_EXPORT const unsigned char GZipVersionString[];
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
NSData *TGGZipData(NSData *data, float level);
|
||||
NSData * _Nullable TGGUnzipData(NSData *data);
|
||||
NSData * _Nonnull TGGZipData(NSData * _Nonnull data, float level);
|
||||
NSData * _Nullable TGGUnzipData(NSData * _Nonnull data, uint sizeLimit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ NSData *TGGZipData(NSData *data, float level) {
|
||||
return output;
|
||||
}
|
||||
|
||||
NSData * _Nullable TGGUnzipData(NSData *data)
|
||||
NSData * _Nullable TGGUnzipData(NSData *data, uint sizeLimit)
|
||||
{
|
||||
if (data.length == 0 || !TGIsGzippedData(data)) {
|
||||
return nil;
|
||||
@ -61,12 +61,20 @@ NSData * _Nullable TGGUnzipData(NSData *data)
|
||||
int status = Z_OK;
|
||||
output = [NSMutableData dataWithCapacity:data.length * 2];
|
||||
while (status == Z_OK) {
|
||||
if (sizeLimit > 0 && stream.total_out > sizeLimit) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (stream.total_out >= output.length) {
|
||||
output.length += data.length / 2;
|
||||
NSUInteger length = output.length + data.length / 2;
|
||||
if (sizeLimit > 0 && length > sizeLimit) {
|
||||
return nil;
|
||||
}
|
||||
output.length = length;
|
||||
}
|
||||
stream.next_out = (uint8_t *)output.mutableBytes + stream.total_out;
|
||||
stream.avail_out = (uInt)(output.length - stream.total_out);
|
||||
status = inflate (&stream, Z_SYNC_FLUSH);
|
||||
status = inflate(&stream, Z_SYNC_FLUSH);
|
||||
}
|
||||
if (inflateEnd(&stream) == Z_OK) {
|
||||
if (status == Z_STREAM_END) {
|
||||
|
@ -214,7 +214,7 @@ private final class AnimatedStickerDirectFrameSource: AnimatedStickerFrameSource
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.currentFrame = 0
|
||||
guard let rawData = TGGUnzipData(data) else {
|
||||
guard let rawData = TGGUnzipData(data, 1024 * 1024) else {
|
||||
return nil
|
||||
}
|
||||
guard let animation = LottieInstance(data: rawData, cacheKey: "") else {
|
||||
|
@ -98,7 +98,7 @@ func fetchCompressedLottieFirstFrameAJpeg(data: Data, size: CGSize, cacheKey: St
|
||||
return
|
||||
}
|
||||
|
||||
let decompressedData = TGGUnzipData(data)
|
||||
let decompressedData = TGGUnzipData(data, 1024 * 1024)
|
||||
if let decompressedData = decompressedData, let player = LottieInstance(data: decompressedData, cacheKey: cacheKey) {
|
||||
if cancelled.with({ $0 }) {
|
||||
return
|
||||
@ -193,7 +193,7 @@ func experimentalConvertCompressedLottieToCombinedMp4(data: Data, size: CGSize,
|
||||
var deltaTime: Double = 0
|
||||
var compressionTime: Double = 0
|
||||
|
||||
let decompressedData = TGGUnzipData(data)
|
||||
let decompressedData = TGGUnzipData(data, 1024 * 1024)
|
||||
if let decompressedData = decompressedData, let player = LottieInstance(data: decompressedData, cacheKey: cacheKey) {
|
||||
let endFrame = Int(player.frameCount)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user