@@ -33,10 +33,11 @@ #import "OFString.h" #import "OFArray.h" #import "OFFile.h" #import "OFURL.h" #import "OFHTTPRequest.h" +#import "OFDataArray.h" #import "OFAutoreleasePool.h" #import "OFHTTPRequestFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" @@ -97,11 +98,11 @@ madvise((void*)str, len, MADV_NORMAL); return -1; } /* We have at minimum a 2 byte character -> check next byte */ - if (OF_UNLIKELY(len < i + 1 || (str[i + 1] & 0xC0) != 0x80)) { + if (OF_UNLIKELY(len <= i + 1 || (str[i + 1] & 0xC0) != 0x80)) { madvise((void*)str, len, MADV_NORMAL); return -1; } /* Check if we have at minimum a 3 byte character */ @@ -109,11 +110,11 @@ i++; continue; } /* We have at minimum a 3 byte char -> check second next byte */ - if (OF_UNLIKELY(len < i + 2 || (str[i + 2] & 0xC0) != 0x80)) { + if (OF_UNLIKELY(len <= i + 2 || (str[i + 2] & 0xC0) != 0x80)) { madvise((void*)str, len, MADV_NORMAL); return -1; } /* Check if we have a 4 byte character */ @@ -121,11 +122,11 @@ i += 2; continue; } /* We have a 4 byte character -> check third next byte */ - if (OF_UNLIKELY(len < i + 3 || (str[i + 3] & 0xC0) != 0x80)) { + if (OF_UNLIKELY(len <= i + 3 || (str[i + 3] & 0xC0) != 0x80)) { madvise((void*)str, len, MADV_NORMAL); return -1; } /* @@ -664,17 +665,20 @@ if (stat([path cString], &s) == -1) @throw [OFOpenFileFailedException newWithClass: isa path: path mode: @"rb"]; + if (s.st_size > SIZE_MAX) + @throw [OFOutOfRangeException newWithClass: isa]; + file = [[OFFile alloc] initWithPath: path mode: @"rb"]; @try { - tmp = [self allocMemoryWithSize: s.st_size]; + tmp = [self allocMemoryWithSize: (size_t)s.st_size]; - [file readExactlyNBytes: s.st_size + [file readExactlyNBytes: (size_t)s.st_size intoBuffer: tmp]; } @finally { [file release]; } } @catch (id e) { @@ -682,11 +686,11 @@ @throw e; } self = [self initWithCString: tmp encoding: encoding - length: s.st_size]; + length: (size_t)s.st_size]; [self freeMemory: tmp]; return self; } @@ -1208,11 +1212,11 @@ return [OFString stringWithCString: string + i length: path_len - i]; } -- (OFString*)stringByDeletingLastPathComponent; +- (OFString*)stringByDeletingLastPathComponent { size_t i, path_len = length; if (path_len == 0) return @""; @@ -1415,11 +1419,11 @@ while (i < length) { of_unichar_t c; size_t clen; - clen = of_string_utf8_to_unicode(string + i, length - 1, &c); + clen = of_string_utf8_to_unicode(string + i, length - i, &c); if (clen == 0 || c > 0x10FFFF) { free(ret); @throw [OFInvalidEncodingException newWithClass: isa]; }