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