X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..a01113dcd0f39d5da295ef82785beff9ed86fe38:/icuSources/common/bytestream.cpp diff --git a/icuSources/common/bytestream.cpp b/icuSources/common/bytestream.cpp index e2142ce1..0d0e4dda 100644 --- a/icuSources/common/bytestream.cpp +++ b/icuSources/common/bytestream.cpp @@ -1,4 +1,6 @@ -// Copyright (C) 2009-2010, International Business Machines +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html +// Copyright (C) 2009-2011, International Business Machines // Corporation and others. All Rights Reserved. // // Copyright 2007 Google Inc. All Rights Reserved. @@ -10,6 +12,8 @@ U_NAMESPACE_BEGIN +ByteSink::~ByteSink() {} + char* ByteSink::GetAppendBuffer(int32_t min_capacity, int32_t /*desired_capacity_hint*/, char* scratch, int32_t scratch_capacity, @@ -29,6 +33,8 @@ CheckedArrayByteSink::CheckedArrayByteSink(char* outbuf, int32_t capacity) size_(0), appended_(0), overflowed_(FALSE) { } +CheckedArrayByteSink::~CheckedArrayByteSink() {} + CheckedArrayByteSink& CheckedArrayByteSink::Reset() { size_ = appended_ = 0; overflowed_ = FALSE; @@ -39,6 +45,12 @@ void CheckedArrayByteSink::Append(const char* bytes, int32_t n) { if (n <= 0) { return; } + if (n > (INT32_MAX - appended_)) { + // TODO: Report as integer overflow, not merely buffer overflow. + appended_ = INT32_MAX; + overflowed_ = TRUE; + return; + } appended_ += n; int32_t available = capacity_ - size_; if (n > available) {