@@ -664,17 +664,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 +685,11 @@ @throw e; } self = [self initWithCString: tmp encoding: encoding - length: s.st_size]; + length: (size_t)s.st_size]; [self freeMemory: tmp]; return self; }