Title: [173666] trunk/Source/WebCore
Revision
173666
Author
[email protected]
Date
2014-09-16 12:22:39 -0700 (Tue, 16 Sep 2014)

Log Message

[Curl] Sometimes incomplete or empty content can be loaded from cache.
https://bugs.webkit.org/show_bug.cgi?id=136855

Patch by [email protected] <[email protected]> on 2014-09-16
Reviewed by Alex Christensen.

Sometimes, when two requests with the same url are started at the same time,
there is a possibility of loading incomplete or empty content from the cache.
This happens because the method CurlCacheEntry::isLoading() is returning the wrong status
in the time period between the headers are received, and the content data is received.
This can be fixed by using a flag for the load status, instead of checking whether
the content file is open.

* platform/network/curl/CurlCacheEntry.cpp:
(WebCore::CurlCacheEntry::CurlCacheEntry): Initialize loading flag.
(WebCore::CurlCacheEntry::isLoading): Return loading flag.
(WebCore::CurlCacheEntry::didFail): Call new method to set loading flag.
(WebCore::CurlCacheEntry::didFinishLoading): Ditto.
(WebCore::CurlCacheEntry::setIsLoading): Added new method to set loading flag.
* platform/network/curl/CurlCacheEntry.h: Added loading flag and new method to set it.
* platform/network/curl/CurlCacheManager.cpp:
(WebCore::CurlCacheManager::didReceiveResponse): Call new method to set loading flag.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (173665 => 173666)


--- trunk/Source/WebCore/ChangeLog	2014-09-16 18:28:57 UTC (rev 173665)
+++ trunk/Source/WebCore/ChangeLog	2014-09-16 19:22:39 UTC (rev 173666)
@@ -1,3 +1,27 @@
+2014-09-16  [email protected]  <[email protected]>
+
+        [Curl] Sometimes incomplete or empty content can be loaded from cache.
+        https://bugs.webkit.org/show_bug.cgi?id=136855
+
+        Reviewed by Alex Christensen.
+
+        Sometimes, when two requests with the same url are started at the same time,
+        there is a possibility of loading incomplete or empty content from the cache.
+        This happens because the method CurlCacheEntry::isLoading() is returning the wrong status
+        in the time period between the headers are received, and the content data is received.
+        This can be fixed by using a flag for the load status, instead of checking whether
+        the content file is open. 
+
+        * platform/network/curl/CurlCacheEntry.cpp:
+        (WebCore::CurlCacheEntry::CurlCacheEntry): Initialize loading flag.
+        (WebCore::CurlCacheEntry::isLoading): Return loading flag.
+        (WebCore::CurlCacheEntry::didFail): Call new method to set loading flag.
+        (WebCore::CurlCacheEntry::didFinishLoading): Ditto.
+        (WebCore::CurlCacheEntry::setIsLoading): Added new method to set loading flag.
+        * platform/network/curl/CurlCacheEntry.h: Added loading flag and new method to set it.
+        * platform/network/curl/CurlCacheManager.cpp:
+        (WebCore::CurlCacheManager::didReceiveResponse): Call new method to set loading flag.
+
 2014-09-16  Chris Dumez  <[email protected]>
 
         Rename Node::nodeIndex() to computeNodeIndex() for clarity

Modified: trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp (173665 => 173666)


--- trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp	2014-09-16 18:28:57 UTC (rev 173665)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp	2014-09-16 19:22:39 UTC (rev 173666)
@@ -53,6 +53,7 @@
     , m_entrySize(0)
     , m_expireDate(-1)
     , m_headerParsed(false)
+    , m_isLoading(false)
     , m_job(job)
 {
     generateBaseFilename(url.latin1());
@@ -69,9 +70,9 @@
     closeContentFile();
 }
 
-bool CurlCacheEntry::isLoading()
+bool CurlCacheEntry::isLoading() const
 {
-    return isHandleValid(m_contentFile);
+    return m_isLoading;
 }
 
 // Cache manager should invalidate the entry on false
@@ -115,7 +116,9 @@
     if (!loadFileToBuffer(m_contentFilename, buffer))
         return false;
 
-    job->getInternal()->client()->didReceiveData(job, buffer.data(), buffer.size(), 0);
+    if (buffer.size())
+        job->getInternal()->client()->didReceiveData(job, buffer.data(), buffer.size(), 0);
+
     return true;
 }
 
@@ -199,12 +202,12 @@
 void CurlCacheEntry::didFail()
 {
     // The cache manager will call invalidate()
-    closeContentFile();
+    setIsLoading(false);
 }
 
 void CurlCacheEntry::didFinishLoading()
 {
-    closeContentFile();
+    setIsLoading(false);
 }
 
 void CurlCacheEntry::generateBaseFilename(const CString& url)
@@ -346,6 +349,15 @@
     return true;
 }
 
+void CurlCacheEntry::setIsLoading(bool isLoading)
+{
+    m_isLoading = isLoading;
+    if (m_isLoading)
+        openContentFile();
+    else
+        closeContentFile();
+}
+
 size_t CurlCacheEntry::entrySize()
 {
     if (!m_entrySize) {

Modified: trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h (173665 => 173666)


--- trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h	2014-09-16 18:28:57 UTC (rev 173665)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h	2014-09-16 19:22:39 UTC (rev 173666)
@@ -45,7 +45,7 @@
     ~CurlCacheEntry();
 
     bool isCached();
-    bool isLoading();
+    bool isLoading() const;
     size_t entrySize();
     HTTPHeaderMap& requestHeaders() { return m_requestHeaders; }
 
@@ -61,6 +61,8 @@
 
     bool parseResponseHeaders(const ResourceResponse&);
 
+    void setIsLoading(bool);
+
     const ResourceHandle* getJob() const { return m_job; }
 
 private:
@@ -73,6 +75,7 @@
     size_t m_entrySize;
     double m_expireDate;
     bool m_headerParsed;
+    bool m_isLoading;
 
     ResourceResponse m_cachedResponse;
     HTTPHeaderMap m_requestHeaders;

Modified: trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp (173665 => 173666)


--- trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp	2014-09-16 18:28:57 UTC (rev 173665)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp	2014-09-16 19:22:39 UTC (rev 173666)
@@ -218,6 +218,7 @@
         auto cacheEntry = std::make_unique<CurlCacheEntry>(url, &job, m_cacheDir);
         bool cacheable = cacheEntry->parseResponseHeaders(response);
         if (cacheable) {
+            cacheEntry->setIsLoading(true);
             m_LRUEntryList.prependOrMoveToFirst(url);
             m_index.set(url, WTF::move(cacheEntry));
             saveResponseHeaders(url, response);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to