Index: trunk/src/VBox/Main/glue/string.cpp
===================================================================
--- trunk/src/VBox/Main/glue/string.cpp	(revision 78416)
+++ trunk/src/VBox/Main/glue/string.cpp	(revision 78417)
@@ -328,5 +328,5 @@
  * @param   a_pcszSrc   The source string.
  * @param   a_offSrc    Start offset to copy from.
- * @param   a_cchSrc    The source string.
+ * @param   a_cchSrc    How much to copy
  * @returns S_OK or E_OUTOFMEMORY.
  *
@@ -336,4 +336,5 @@
 HRESULT Utf8Str::copyFromExNComRC(const char *a_pcszSrc, size_t a_offSrc, size_t a_cchSrc)
 {
+    Assert(!a_cchSrc || !m_psz || (uintptr_t)&a_pcszSrc[a_offSrc] - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated);
     cleanup();
     if (a_cchSrc)
Index: trunk/src/VBox/Runtime/common/string/ministring.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/string/ministring.cpp	(revision 78416)
+++ trunk/src/VBox/Runtime/common/string/ministring.cpp	(revision 78417)
@@ -56,4 +56,5 @@
 RTCString &RTCString::assign(const RTCString &a_rSrc)
 {
+    Assert(&a_rSrc != this);
     size_t const cchSrc = a_rSrc.length();
     if (cchSrc > 0)
@@ -98,4 +99,6 @@
         if (cchSrc)
         {
+            Assert((uintptr_t)&a_pszSrc - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated);
+
             reserve(cchSrc + 1);
             memcpy(m_psz, a_pszSrc, cchSrc);
@@ -116,4 +119,6 @@
         if (cchSrc)
         {
+            Assert((uintptr_t)&a_pszSrc - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated);
+
             int rc = reserveNoThrow(cchSrc + 1);
             if (RT_SUCCESS(rc))
@@ -176,28 +181,38 @@
     {
         a_cchSrc = RTStrNLen(a_pszSrc, a_cchSrc);
-        reserve(a_cchSrc + 1);
-        memcpy(m_psz, a_pszSrc, a_cchSrc);
-        m_psz[a_cchSrc] = '\0';
-        m_cch = a_cchSrc;
-    }
-    else
-        setNull();
-    return *this;
-}
-
-int RTCString::assignNoThrow(const char *a_pszSrc, size_t a_cchSrc) RT_NOEXCEPT
-{
-    if (a_cchSrc)
-    {
-        a_cchSrc = RTStrNLen(a_pszSrc, a_cchSrc);
-        int rc = reserveNoThrow(a_cchSrc + 1);
-        if (RT_SUCCESS(rc))
-        {
+        if (a_cchSrc)
+        {
+            Assert((uintptr_t)&a_pszSrc - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated);
+
+            reserve(a_cchSrc + 1);
             memcpy(m_psz, a_pszSrc, a_cchSrc);
             m_psz[a_cchSrc] = '\0';
             m_cch = a_cchSrc;
-            return VINF_SUCCESS;
-        }
-        return rc;
+            return *this;
+        }
+    }
+    setNull();
+    return *this;
+}
+
+int RTCString::assignNoThrow(const char *a_pszSrc, size_t a_cchSrc) RT_NOEXCEPT
+{
+    if (a_cchSrc)
+    {
+        a_cchSrc = RTStrNLen(a_pszSrc, a_cchSrc);
+        if (a_cchSrc)
+        {
+            Assert((uintptr_t)&a_pszSrc - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated);
+
+            int rc = reserveNoThrow(a_cchSrc + 1);
+            if (RT_SUCCESS(rc))
+            {
+                memcpy(m_psz, a_pszSrc, a_cchSrc);
+                m_psz[a_cchSrc] = '\0';
+                m_cch = a_cchSrc;
+                return VINF_SUCCESS;
+            }
+            return rc;
+        }
     }
     setNull();
@@ -433,4 +448,6 @@
     if (cchSrc)
     {
+        Assert((uintptr_t)&pszSrc - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated);
+
         size_t cchThis = length();
         size_t cchBoth = cchThis + cchSrc;
@@ -456,4 +473,6 @@
     if (cchSrc)
     {
+        Assert((uintptr_t)&pszSrc - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated);
+
         size_t cchThis = length();
         size_t cchBoth = cchThis + cchSrc;
@@ -668,4 +687,6 @@
 RTCString &RTCString::replaceWorker(size_t offStart, size_t cchLength, const char *pszSrc, size_t cchSrc)
 {
+    Assert((uintptr_t)&pszSrc - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated || !cchSrc);
+
     /*
      * Our non-standard handling of out_of_range situations.
@@ -710,4 +731,6 @@
 int RTCString::replaceWorkerNoThrow(size_t offStart, size_t cchLength, const char *pszSrc, size_t cchSrc) RT_NOEXCEPT
 {
+    Assert((uintptr_t)&pszSrc - (uintptr_t)m_psz >= (uintptr_t)m_cbAllocated || !cchSrc);
+
     /*
      * Our non-standard handling of out_of_range situations.
