Index: src/OFStdIOStream_Win32Console.m ================================================================== --- src/OFStdIOStream_Win32Console.m +++ src/OFStdIOStream_Win32Console.m @@ -106,18 +106,22 @@ void *pool = objc_autoreleasePoolPush(); char *buffer = buffer_; of_char16_t *UTF16; size_t j = 0; + if (length > sizeof(UINT32_MAX)) + @throw [OFOutOfRangeException exception]; + UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t) count: length]; @try { DWORD UTF16Len; OFDataArray *rest = nil; size_t i = 0; - if (!ReadConsoleW(_handle, UTF16, length, &UTF16Len, NULL)) + if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len, + NULL)) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length * 2]; if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) { @@ -224,12 +228,12 @@ if (_incompleteUTF8SurrogateLen > 0) { of_unichar_t c; of_char16_t UTF16[2]; ssize_t UTF8Len; - size_t toCopy, UTF16Len; - DWORD written; + size_t toCopy; + DWORD UTF16Len, written; UTF8Len = -of_string_utf8_decode( _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c); OF_ENSURE(UTF8Len > 0); @@ -311,15 +315,18 @@ tmp[j++] = c; i += UTF8Len; } - if (!WriteConsoleW(_handle, tmp, j, &written, NULL) || + if (j > UINT32_MAX) + @throw [OFOutOfRangeException exception]; + + if (!WriteConsoleW(_handle, tmp, (DWORD)j, &written, NULL) || written != j) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2]; } @finally { [self freeMemory: tmp]; } } @end