@@ -39,10 +39,11 @@ #ifdef OF_HAVE_SOCKETS # import "OFHTTPRequestFailedException.h" #endif #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" +#import "OFInvalidServerReplyException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" @@ -158,11 +159,12 @@ OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; of_offset_t size = [[OFFileManager defaultManager] sizeOfFileAtPath: path]; - if (size > SIZE_MAX) + if (sizeof(of_offset_t) > sizeof(size_t) && + size > (of_offset_t)SIZE_MAX) @throw [OFOutOfRangeException exception]; self = [self initWithItemSize: 1 capacity: (size_t)size]; @@ -218,11 +220,11 @@ OFHTTPResponse *response = [client performRequest: request]; size_t pageSize; char *buffer; OFDictionary *headers; - OFString *contentLength; + OFString *contentLengthString; if ([response statusCode] != 200) @throw [OFHTTPRequestFailedException exceptionWithRequest: request response: response]; @@ -243,16 +245,24 @@ } @finally { [self freeMemory: buffer]; } headers = [response headers]; - if ((contentLength = - [headers objectForKey: @"Content-Length"]) != nil) - if ([self count] != - [contentLength decimalValue]) + if ((contentLengthString = + [headers objectForKey: @"Content-Length"]) != nil) { + intmax_t contentLength = + [contentLengthString decimalValue]; + + if (contentLength < 0) + @throw [OFInvalidServerReplyException + exception]; + + if ((uintmax_t)[self count] != + (uintmax_t)contentLength) @throw [OFTruncatedDataException exception]; + } } @catch (id e) { [self release]; @throw e; } } else