From 8231f79977606d3249cbeb124a92e7347fe6f64c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 21 Mar 2017 09:49:51 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20check=20content=20length=20head?= =?UTF-8?q?er=20until=20we=E2=80=99ve=20received=20at=20least=20one=20byte?= =?UTF-8?q?=20of=20the=20attachment=20download.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- src/Messages/Attachments/OWSAttachmentsProcessor.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Messages/Attachments/OWSAttachmentsProcessor.m b/src/Messages/Attachments/OWSAttachmentsProcessor.m index 917ae8c28..577a82741 100644 --- a/src/Messages/Attachments/OWSAttachmentsProcessor.m +++ b/src/Messages/Attachments/OWSAttachmentsProcessor.m @@ -242,7 +242,9 @@ NS_ASSUME_NONNULL_BEGIN task = [manager GET:location parameters:nil progress:^(NSProgress *_Nonnull progress) { - if (!hasCheckedContentLength) { + // Once we've received some bytes of the download, check the content length + // header for the download. + if (progress.completedUnitCount > 0 && !hasCheckedContentLength) { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response; if ([httpResponse isKindOfClass:[NSHTTPURLResponse class]]) { NSDictionary *headers = [httpResponse allHeaderFields]; @@ -269,7 +271,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(progress != nil); if (progress.totalUnitCount > kMaxDownloadSize || progress.completedUnitCount > kMaxDownloadSize) { - // A malicious service might send an incorrect content length header, + // A malicious service might send a misleading content length header, // so.... // // If the current downloaded bytes or the expected total byes