Bug 443067 - Disk Cache overflow when downloading large files. r=bz
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 15 Apr 2010 02:19:00 -0400
changeset 43568 eb8e32b47158c2fd932d1ae96de807c32229e3ee
parent 43567 84c1cc66b41128c4764e202ce4069e19a7f9b5b0
child 43569 2bb9839485c0b97086e9fbbe4ed8f7e0cbc3a978
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs443067
milestone1.9.3a6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 443067 - Disk Cache overflow when downloading large files. r=bz
netwerk/cache/nsDiskCacheDevice.cpp
netwerk/cache/nsDiskCacheMap.h
--- a/netwerk/cache/nsDiskCacheDevice.cpp
+++ b/netwerk/cache/nsDiskCacheDevice.cpp
@@ -779,18 +779,18 @@ nsDiskCacheDevice::OnDataSizeChange(nsCa
 #endif
             nsCacheService::DoomEntry(entry);
         NS_ASSERTION(NS_SUCCEEDED(rv),"DoomEntry() failed.");
         return NS_ERROR_ABORT;
     }
 
     PRUint32  sizeK = ((entry->DataSize() + 0x03FF) >> 10); // round up to next 1k
 
-    NS_ASSERTION(sizeK < USHRT_MAX, "data size out of range");
-    NS_ASSERTION(newSizeK < USHRT_MAX, "data size out of range");
+    NS_ASSERTION(sizeK <= USHRT_MAX, "data size out of range");
+    NS_ASSERTION(newSizeK <= USHRT_MAX, "data size out of range");
 
     // pre-evict entries to make space for new data
     PRUint32  targetCapacity = mCacheCapacity > (newSizeK - sizeK)
                              ? mCacheCapacity - (newSizeK - sizeK)
                              : 0;
     EvictDiskCacheEntries(targetCapacity);
     
     return NS_OK;
--- a/netwerk/cache/nsDiskCacheMap.h
+++ b/netwerk/cache/nsDiskCacheMap.h
@@ -85,17 +85,17 @@ struct nsDiskCacheEntry;
  *****************************************************************************/
 
 #define BLOCK_SIZE_FOR_INDEX(index)  ((index) ? (256 << (2 * ((index) - 1))) : 0)
 
 // Min and max values for the number of records in the DiskCachemap
 #define kMinRecordCount    512
 
 #define kSeparateFile      0
-#define kMaxDataFileSize   0x4000000   // 64 MiB
+#define kMaxDataFileSize   0x3FFFC00   // 65535 KiB (see bug #443067)
 #define kBuckets           (1 << 5)    // must be a power of 2!
 
 class nsDiskCacheRecord {
 
 private:
     PRUint32    mHashNumber;
     PRUint32    mEvictionRank;
     PRUint32    mDataLocation;
@@ -329,17 +329,17 @@ class nsDiskCacheRecordVisitor {
 
 
 /******************************************************************************
  *  nsDiskCacheHeader
  *****************************************************************************/
 
 struct nsDiskCacheHeader {
     PRUint32    mVersion;                           // cache version.
-    PRUint32    mDataSize;                          // size of cache in units of 256bytes.
+    PRUint32    mDataSize;                          // size of cache in units of 1024bytes.
     PRInt32     mEntryCount;                        // number of entries stored in cache.
     PRUint32    mIsDirty;                           // dirty flag.
     PRInt32     mRecordCount;                       // Number of records
     PRUint32    mEvictionRank[kBuckets];            // Highest EvictionRank of the bucket
     PRUint32    mBucketUsage[kBuckets];             // Number of used entries in the bucket
   
     nsDiskCacheHeader()
         : mVersion(nsDiskCache::kCurrentVersion)