@@ -108,11 +108,16 @@ contentLength = [headers objectForKey: @"Content-Length"]; if (contentLength != nil) { _hasContentLength = true; @try { - _toRead = (size_t)[contentLength decimalValue]; + intmax_t toRead = [contentLength decimalValue]; + + if (toRead > SIZE_MAX) + @throw [OFOutOfRangeException exception]; + + _toRead = (size_t)toRead; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerReplyException exception]; } } } @@ -185,12 +190,16 @@ if (range.location != OF_NOT_FOUND) line = [line substringWithRange: of_range(0, range.location)]; @try { - _toRead = - (size_t)[line hexadecimalValue]; + uintmax_t toRead = [line hexadecimalValue]; + + if (toRead > SIZE_MAX) + @throw [OFOutOfRangeException exception]; + + _toRead = (size_t)toRead; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerReplyException exception]; } if (_toRead == 0) {