@@ -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];