Modified: trunk/Source/WebCore/ChangeLog (169114 => 169115)
--- trunk/Source/WebCore/ChangeLog 2014-05-20 16:59:53 UTC (rev 169114)
+++ trunk/Source/WebCore/ChangeLog 2014-05-20 17:01:47 UTC (rev 169115)
@@ -1,3 +1,24 @@
+2014-05-20 [email protected] <[email protected]>
+
+ [Curl] Invalid content in cache file, causes broken rendering.
+ https://bugs.webkit.org/show_bug.cgi?id=133069
+
+ Reviewed by Brent Fulgham.
+
+ When data for a url is received as multiple parts, the cache file for the url is truncated when opened for writing,
+ and will only contain the last part of data received.
+ This is fixed by only opening the file once, and close it after all data has been received.
+
+ * platform/network/curl/CurlCacheEntry.cpp:
+ (WebCore::CurlCacheEntry::CurlCacheEntry): Initialize cache file handle member.
+ (WebCore::CurlCacheEntry::~CurlCacheEntry): Close cache file.
+ (WebCore::CurlCacheEntry::saveCachedData): Only open cache file once to avoid truncating.
+ (WebCore::CurlCacheEntry::didFail): Close cache file.
+ (WebCore::CurlCacheEntry::didFinishLoading): Ditto.
+ (WebCore::CurlCacheEntry::openContentFile): Added method to open cache file.
+ (WebCore::CurlCacheEntry::closeContentFile): Added method to close cache file.
+ * platform/network/curl/CurlCacheEntry.h: Added file handle member, and methods to open and close cache file.
+
2014-05-20 Radu Stavila <[email protected]>
[CSS Regions] Block incorrectly sized when containing an unsplittable box
Modified: trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp (169114 => 169115)
--- trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp 2014-05-20 16:59:53 UTC (rev 169114)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.cpp 2014-05-20 17:01:47 UTC (rev 169115)
@@ -30,7 +30,6 @@
#include "CurlCacheEntry.h"
-#include "FileSystem.h"
#include "HTTPHeaderMap.h"
#include "HTTPParsers.h"
#include "Logging.h"
@@ -49,6 +48,7 @@
CurlCacheEntry::CurlCacheEntry(const String& url, const String& cacheDir)
: m_headerFilename(cacheDir)
, m_contentFilename(cacheDir)
+ , m_contentFile(invalidPlatformFileHandle)
, m_entrySize(0)
, m_expireDate(-1)
, m_headerParsed(false)
@@ -64,6 +64,7 @@
CurlCacheEntry::~CurlCacheEntry()
{
+ closeContentFile();
}
// Cache manager should invalidate the entry on false
@@ -90,16 +91,12 @@
bool CurlCacheEntry::saveCachedData(const char* data, size_t size)
{
- PlatformFileHandle contentFile = openFile(m_contentFilename, OpenForWrite);
- if (!isHandleValid(contentFile)) {
- LOG(Network, "Cache Error: Could not open %s for write\n", m_contentFilename.latin1().data());
+ if (!openContentFile())
return false;
- }
// Append
- seekFile(contentFile, 0, SeekFromEnd);
- writeToFile(contentFile, data, size);
- closeFile(contentFile);
+ writeToFile(m_contentFile, data, size);
+
return true;
}
@@ -195,11 +192,12 @@
void CurlCacheEntry::didFail()
{
// The cache manager will call invalidate()
+ closeContentFile();
}
void CurlCacheEntry::didFinishLoading()
{
- // Nothing to do here yet
+ closeContentFile();
}
void CurlCacheEntry::generateBaseFilename(const CString& url)
@@ -361,6 +359,32 @@
return m_entrySize;
}
+
+bool CurlCacheEntry::openContentFile()
+{
+ if (isHandleValid(m_contentFile))
+ return true;
+
+ m_contentFile = openFile(m_contentFilename, OpenForWrite);
+
+ if (isHandleValid(m_contentFile))
+ return true;
+
+ LOG(Network, "Cache Error: Could not open %s for write\n", m_contentFilename.latin1().data());
+ return false;
}
+bool CurlCacheEntry::closeContentFile()
+{
+ if (!isHandleValid(m_contentFile))
+ return true;
+
+ closeFile(m_contentFile);
+ m_contentFile = invalidPlatformFileHandle;
+
+ return true;
+}
+
+}
+
#endif
Modified: trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h (169114 => 169115)
--- trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h 2014-05-20 16:59:53 UTC (rev 169114)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h 2014-05-20 17:01:47 UTC (rev 169115)
@@ -27,6 +27,7 @@
#ifndef CurlCacheEntry_h
#define CurlCacheEntry_h
+#include "FileSystem.h"
#include "HTTPHeaderMap.h"
#include "ResourceHandle.h"
#include "ResourceRequest.h"
@@ -64,6 +65,8 @@
String m_headerFilename;
String m_contentFilename;
+ PlatformFileHandle m_contentFile;
+
size_t m_entrySize;
double m_expireDate;
bool m_headerParsed;
@@ -74,6 +77,9 @@
void generateBaseFilename(const CString& url);
bool loadFileToBuffer(const String& filepath, Vector<char>& buffer);
bool loadResponseHeaders();
+
+ bool openContentFile();
+ bool closeContentFile();
};
}