Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -1326,5 +1326,12 @@ /** * \return The status code of the HTTP request */ - (short)statusCode; @end + +/** + * \brief An exception indicating that data was truncated while it should not + * have been truncated. + */ +@interface OFTruncatedDataException: OFException +@end Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -1972,5 +1972,19 @@ - (short)statusCode { return statusCode; } @end + +@implementation OFTruncatedDataException +- (OFString*)description +{ + if (description != nil) + return description; + + description = [[OFString alloc] initWithFormat: + @"Truncated data was received or produced in class %s while it " + @"should not have been truncated!", class_getName(inClass)]; + + return description; +} +@end Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -261,10 +261,25 @@ [s_headers setObject: value forKey: key]; } data = [[sock readDataArrayTillEndOfStream] retain]; + + if ([s_headers objectForKey: @"Content-Length"] != nil) { + intmax_t cl; + + cl = [[s_headers objectForKey: @"Content-Length"] + decimalValue]; + + if (cl > SIZE_MAX) + @throw [OFOutOfRangeException + newWithClass: isa]; + + if (cl != [data count]) + @throw [OFTruncatedDataException + newWithClass: isa]; + } result = [[OFHTTPRequestResult alloc] initWithStatusCode: status headers: s_headers data: data];