]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/bytestream.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / common / bytestream.cpp
index e2142ce1eae658534b019ac7f33e7f328f7d1afe..0d0e4dda39b088720d1d7e4e9df7b98caa858e4f 100644 (file)
@@ -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) {