You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2015/05/16 06:24:38 UTC

svn commit: r1679682 - in /subversion/branches/1.9-cache-improvements: ./ subversion/libsvn_subr/cache-membuffer.c

Author: stefan2
Date: Sat May 16 04:24:38 2015
New Revision: 1679682

URL: http://svn.apache.org/r1679682
Log:
On the 1.9-cache-improvements:
Merge latest fixes r1679679 and r1679681 from 1.10-cache-improvements.
There were no conflicts.

Modified:
    subversion/branches/1.9-cache-improvements/   (props changed)
    subversion/branches/1.9-cache-improvements/subversion/libsvn_subr/cache-membuffer.c

Propchange: subversion/branches/1.9-cache-improvements/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat May 16 04:24:38 2015
@@ -1,4 +1,4 @@
-/subversion/branches/1.10-cache-improvements:1675666-1677522
+/subversion/branches/1.10-cache-improvements:1675666-1677522,1679679,1679681
 /subversion/branches/1.5.x-r30215:870312
 /subversion/branches/1.7.x-fs-verify:1146708,1161180
 /subversion/branches/10Gb:1388102,1388163-1388190,1388195,1388202,1388205,1388211,1388276,1388362,1388375,1388394,1388636,1388639-1388640,1388643-1388644,1388654,1388720,1388789,1388795,1388801,1388805,1388807,1388810,1388816,1389044,1389276,1389289,1389662,1389867,1390017,1390209,1390216,1390407,1390409,1390414,1390419,1390955

Modified: subversion/branches/1.9-cache-improvements/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.9-cache-improvements/subversion/libsvn_subr/cache-membuffer.c?rev=1679682&r1=1679681&r2=1679682&view=diff
==============================================================================
--- subversion/branches/1.9-cache-improvements/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/branches/1.9-cache-improvements/subversion/libsvn_subr/cache-membuffer.c Sat May 16 04:24:38 2015
@@ -1254,7 +1254,9 @@ find_entry(svn_membuffer_t *cache,
                            entry->key.key_len) == 0)
                   return entry;
 
-                /* Key conflict. Drop the current entry. */
+                /* Key conflict. The entry to find cannot be anywhere else.
+                 * Therefore, it is not cached. */
+                return NULL;
               }
 
             /* need to empty that entry */
@@ -2610,15 +2612,34 @@ combine_long_key(svn_membuffer_cache_t *
 {
   apr_uint32_t *digest_buffer;
   char *key_copy;
-  apr_size_t prefix_len = cache->prefix.entry_key.key_len;
-  apr_size_t aligned_key_len;
+  apr_uint32_t prefix_len = cache->prefix.entry_key.key_len;
+  apr_uint32_t aligned_key_len;
 
   /* handle variable-length keys */
   if (key_len == APR_HASH_KEY_STRING)
     key_len = strlen((const char *) key);
 
+  /* Paranoia: Ridiculously long keys.
+   *
+   * We can't cache combined keys of 4GB and longer anyways.  So, putting
+   * a cap on them just above the maximum cachable value keeps them still
+   * non-cachable but allows us to cast to u32.
+   */
+  assert(MAX_ITEM_SIZE < APR_UINT32_MAX);
+  if (APR_UINT32_MAX - prefix_len <= key_len)
+    {
+      /* Non-cachable. Cap values. No data alignment needed. */
+      key_len = APR_UINT32_MAX - prefix_len;
+      aligned_key_len = key_len;
+    }
+  else
+    {
+      /* Cast is safe.
+       * Key and item may be cachable, so item alignment is necessary. */
+      aligned_key_len = ALIGN_VALUE((apr_uint32_t)key_len);
+    }
+
   /* Combine keys. */
-  aligned_key_len = ALIGN_VALUE(key_len);
   svn_membuf__ensure(&cache->combined_key.full_key,
                      aligned_key_len + prefix_len);
 
@@ -3145,6 +3166,19 @@ svn_cache__create_membuffer_cache(svn_ca
   prefix_orig_len = strlen(prefix) + 1;
   prefix_len = ALIGN_VALUE(prefix_orig_len);
 
+  assert(MAX_ITEM_SIZE < APR_UINT32_MAX);
+  if (prefix_len > MAX_ITEM_SIZE)
+    {
+      /* We should never ever get here but the above check makes the cast
+       * to u32 further down safe.  We may also catch missing parameter
+       * initializations here. */
+      return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
+                              "Cache prefix length of %" APR_UINT64_T_FMT 
+                              " exceeds maximum of %" APR_UINT64_T_FMT 
+                              " bytes\n", (apr_uint64_t)prefix_len,
+                              (apr_uint64_t)MAX_ITEM_SIZE);
+    }
+
   svn_membuf__create(&cache->prefix.full_key, prefix_len, result_pool);
   memcpy((char *)cache->prefix.full_key.data, prefix, prefix_orig_len);
   memset((char *)cache->prefix.full_key.data + prefix_orig_len, 0,
@@ -3158,7 +3192,7 @@ svn_cache__create_membuffer_cache(svn_ca
                        scratch_pool));
   memcpy(cache->prefix.entry_key.fingerprint, checksum->digest,
          sizeof(cache->prefix.entry_key.fingerprint));
-  cache->prefix.entry_key.key_len = prefix_len;
+  cache->prefix.entry_key.key_len = (apr_uint32_t)prefix_len;
 
   /* Initialize the combined key. Pre-allocate some extra room in the full
    * key such that we probably don't need to re-alloc. */