Don’t check content length header until we’ve received at least one byte of the attachment download.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 2c61943537
commit 8231f79977

@ -242,7 +242,9 @@ NS_ASSUME_NONNULL_BEGIN
task = [manager GET:location task = [manager GET:location
parameters:nil parameters:nil
progress:^(NSProgress *_Nonnull progress) { 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; NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
if ([httpResponse isKindOfClass:[NSHTTPURLResponse class]]) { if ([httpResponse isKindOfClass:[NSHTTPURLResponse class]]) {
NSDictionary *headers = [httpResponse allHeaderFields]; NSDictionary *headers = [httpResponse allHeaderFields];
@ -269,7 +271,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(progress != nil); OWSAssert(progress != nil);
if (progress.totalUnitCount > kMaxDownloadSize || progress.completedUnitCount > kMaxDownloadSize) { 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.... // so....
// //
// If the current downloaded bytes or the expected total byes // If the current downloaded bytes or the expected total byes

Loading…
Cancel
Save