From 31a1a69d2b92d33a33ca8915a9481927074ae45e Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 21 Feb 2019 13:29:19 +0400 Subject: [PATCH] Fixed int overflow on auto-download preset comparison --- TelegramUI/ChatController.swift | 4 ++++ .../ChatMessageInteractiveInstantVideoNode.swift | 16 +++++++++++----- TelegramUI/ID3Artwork.m | 8 -------- TelegramUI/InstantVideoRadialStatusNode.swift | 9 +++------ TelegramUI/MediaAutoDownloadSettings.swift | 4 ++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/TelegramUI/ChatController.swift b/TelegramUI/ChatController.swift index e2a2810892..e8d802ab27 100644 --- a/TelegramUI/ChatController.swift +++ b/TelegramUI/ChatController.swift @@ -5465,6 +5465,10 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal } func previewingController(from sourceView: UIView, for location: CGPoint) -> (UIViewController, CGRect)? { + guard let view = self.chatDisplayNode.view.hitTest(location, with: nil), view.isDescendant(of: self.chatDisplayNode.historyNode.view) else { + return nil + } + let historyPoint = sourceView.convert(location, to: self.chatDisplayNode.historyNode.view) var result: (Message, ChatMessagePeekPreviewContent)? self.chatDisplayNode.historyNode.forEachItemNode { itemNode in diff --git a/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift b/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift index 6958c1ba42..ae36cf4c35 100644 --- a/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift +++ b/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift @@ -34,7 +34,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { private var item: ChatMessageBubbleContentItem? private var automaticDownload: Bool? - var telegramFile: TelegramMediaFile? + var media: TelegramMediaFile? private var secretProgressIcon: UIImage? private let fetchDisposable = MetaDisposable() @@ -112,7 +112,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { } func asyncLayout() -> (_ item: ChatMessageBubbleContentItem, _ width: CGFloat, _ displaySize: CGSize, _ statusType: ChatMessageInteractiveInstantVideoNodeStatusType, _ automaticDownload: Bool) -> (ChatMessageInstantVideoItemLayoutResult, (ChatMessageInstantVideoItemLayoutData, ContainedViewLayoutTransition) -> Void) { - let previousFile = self.telegramFile + let previousFile = self.media let currentItem = self.item let previousAutomaticDownload = self.automaticDownload @@ -283,7 +283,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { strongSelf.secretVideoPlaceholderBackground.image = secretVideoPlaceholderBackgroundImage } - strongSelf.telegramFile = updatedFile + strongSelf.media = updatedFile if let infoBackgroundImage = strongSelf.infoBackgroundNode.image, let muteImage = strongSelf.muteIconNode.image { let infoWidth = muteImage.size.width @@ -603,10 +603,16 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { return } if self.infoBackgroundNode.alpha.isZero { - item.context.sharedContext.mediaManager.playlistControl(.playback(.togglePlayPause), type: .voice) + if let status = self.status, case let .fetchStatus(fetchStatus) = status, case .Remote = fetchStatus { + item.context.sharedContext.mediaManager.playlistControl(.playback(.pause), type: .voice) + self.videoNode?.fetchControl(.fetch) + } else { + item.context.sharedContext.mediaManager.playlistControl(.playback(.togglePlayPause), type: .voice) + } } else { let _ = item.controllerInteraction.openMessage(item.message, .default) } + } override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { @@ -623,7 +629,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { } private func progressPressed() { - guard let item = self.item, let file = self.telegramFile else { + guard let item = self.item, let file = self.media else { return } if let status = self.status { diff --git a/TelegramUI/ID3Artwork.m b/TelegramUI/ID3Artwork.m index a53b5c2a77..6986b72170 100644 --- a/TelegramUI/ID3Artwork.m +++ b/TelegramUI/ID3Artwork.m @@ -16,14 +16,6 @@ const uint8_t ID3v3Artwork[4] = {0x41, 0x50, 0x49, 0x43}; const uint8_t JPGMagic[3] = {0xff, 0xd8, 0xff}; const uint8_t PNGMagic[4] = {0x89, 0x50, 0x4e, 0x47}; -uint32_t getSize(const uint8_t *bytes) { - uint32_t size = CFSwapInt32HostToBig(*(const uint32_t *)(bytes + ID3SizeOffset)); - uint32_t b1 = (size & 0x7F000000) >> 3; - uint32_t b2 = (size & 0x007F0000) >> 2; - uint32_t b3 = (size & 0x00007F00) >> 1; - uint32_t b4 = size & 0x0000007F; - return b1 + b2 + b3 + b4; -} uint32_t frameOffsetForVersion(uint8_t version) { return version == 2 ? ID3v2FrameOffset : ID3v3FrameOffset; diff --git a/TelegramUI/InstantVideoRadialStatusNode.swift b/TelegramUI/InstantVideoRadialStatusNode.swift index 09af713305..f054f1b2cc 100644 --- a/TelegramUI/InstantVideoRadialStatusNode.swift +++ b/TelegramUI/InstantVideoRadialStatusNode.swift @@ -112,10 +112,10 @@ final class InstantVideoRadialStatusNode: ASDisplayNode { if let (timestamp, duration, baseRate) = timestampAndDuration, let statusValue = self.statusValue { let progress = CGFloat(timestamp / duration) - if progress.isNaN || !progress.isFinite || statusValue.generationTimestamp.isZero { + if progress.isNaN || !progress.isFinite { self.pop_removeAnimation(forKey: "progress") self.effectiveProgress = 0.0 - } else if statusValue.status != .playing { + } else if statusValue.status != .playing || statusValue.generationTimestamp.isZero { self.pop_removeAnimation(forKey: "progress") self.effectiveProgress = progress } else { @@ -130,14 +130,11 @@ final class InstantVideoRadialStatusNode: ASDisplayNode { (node as! InstantVideoRadialStatusNode).effectiveProgress = values!.pointee } property?.threshold = 0.01 - }) as! POPAnimatableProperty + }) as? POPAnimatableProperty animation.fromValue = progress as NSNumber animation.toValue = 1.0 as NSNumber animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) animation.duration = max(0.0, duration - timestamp) / baseRate - animation.completionBlock = { [weak self] _, _ in - - } animation.beginTime = statusValue.generationTimestamp self.pop_add(animation, forKey: "progress") } diff --git a/TelegramUI/MediaAutoDownloadSettings.swift b/TelegramUI/MediaAutoDownloadSettings.swift index f59b8ab3f9..6083edfc61 100644 --- a/TelegramUI/MediaAutoDownloadSettings.swift +++ b/TelegramUI/MediaAutoDownloadSettings.swift @@ -95,8 +95,8 @@ public struct MediaAutoDownloadCategories: PostboxCoding, Equatable, Comparable } public static func < (lhs: MediaAutoDownloadCategories, rhs: MediaAutoDownloadCategories) -> Bool { - let lhsSizeLimit = (isAutodownloadEnabledForAnyPeerType(category: lhs.video) ? lhs.video.sizeLimit : 0) + (isAutodownloadEnabledForAnyPeerType(category: lhs.file) ? lhs.file.sizeLimit : 0) - let rhsSizeLimit = (isAutodownloadEnabledForAnyPeerType(category: rhs.video) ? rhs.video.sizeLimit : 0) + (isAutodownloadEnabledForAnyPeerType(category: rhs.file) ? rhs.file.sizeLimit : 0) + let lhsSizeLimit: Int64 = Int64((isAutodownloadEnabledForAnyPeerType(category: lhs.video) ? lhs.video.sizeLimit : 0)) + Int64((isAutodownloadEnabledForAnyPeerType(category: lhs.file) ? lhs.file.sizeLimit : 0)) + let rhsSizeLimit: Int64 = Int64((isAutodownloadEnabledForAnyPeerType(category: rhs.video) ? rhs.video.sizeLimit : 0)) + Int64((isAutodownloadEnabledForAnyPeerType(category: rhs.file) ? rhs.file.sizeLimit : 0)) return lhsSizeLimit < rhsSizeLimit } }