Title: [153485] trunk/Source
Revision
153485
Author
par...@webkit.org
Date
2013-07-30 12:01:07 -0700 (Tue, 30 Jul 2013)

Log Message

[WIN] Remove dependency on CoreFoundation from DownloadBundle
https://bugs.webkit.org/show_bug.cgi?id=119247

Reviewed by Anders Carlsson.

* platform/network/cf/DownloadBundle.h:
* platform/network/curl/DownloadBundle.h:
* platform/network/win/DownloadBundleWin.cpp:
(WebCore::DownloadBundle::magicNumber):
(WebCore::DownloadBundle::appendResumeData):
(WebCore::DownloadBundle::extractResumeData):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (153484 => 153485)


--- trunk/Source/WebCore/ChangeLog	2013-07-30 18:54:58 UTC (rev 153484)
+++ trunk/Source/WebCore/ChangeLog	2013-07-30 19:01:07 UTC (rev 153485)
@@ -1,5 +1,19 @@
 2013-07-30  Patrick Gansterer  <par...@webkit.org>
 
+        [WIN] Remove dependency on CoreFoundation from DownloadBundle
+        https://bugs.webkit.org/show_bug.cgi?id=119247
+
+        Reviewed by Anders Carlsson.
+
+        * platform/network/cf/DownloadBundle.h:
+        * platform/network/curl/DownloadBundle.h:
+        * platform/network/win/DownloadBundleWin.cpp:
+        (WebCore::DownloadBundle::magicNumber):
+        (WebCore::DownloadBundle::appendResumeData):
+        (WebCore::DownloadBundle::extractResumeData):
+
+2013-07-30  Patrick Gansterer  <par...@webkit.org>
+
         Move WindowsExtras.h from WebCore to WTF
         https://bugs.webkit.org/show_bug.cgi?id=118125
 

Modified: trunk/Source/WebCore/platform/network/cf/DownloadBundle.h (153484 => 153485)


--- trunk/Source/WebCore/platform/network/cf/DownloadBundle.h	2013-07-30 18:54:58 UTC (rev 153484)
+++ trunk/Source/WebCore/platform/network/cf/DownloadBundle.h	2013-07-30 19:01:07 UTC (rev 153485)
@@ -27,14 +27,13 @@
 #define DownloadBundle_h
 
 #include <wtf/Forward.h>
+#include <wtf/Vector.h>
 
-typedef const struct __CFData* CFDataRef;
-
 namespace WebCore {
 namespace DownloadBundle {
 
-bool appendResumeData(CFDataRef resumeData, const String& bundlePath);
-CFDataRef extractResumeData(const String& bundlePath);
+bool appendResumeData(const char*, uint32_t, const String& bundlePath);
+bool extractResumeData(const String& bundlePath, Vector<char>& resumeData);
 const String& fileExtension();
 
 } // namespace DownloadBundle

Modified: trunk/Source/WebCore/platform/network/curl/DownloadBundle.h (153484 => 153485)


--- trunk/Source/WebCore/platform/network/curl/DownloadBundle.h	2013-07-30 18:54:58 UTC (rev 153484)
+++ trunk/Source/WebCore/platform/network/curl/DownloadBundle.h	2013-07-30 19:01:07 UTC (rev 153485)
@@ -27,14 +27,13 @@
 #define DownloadBundle_h
 
 #include <wtf/Forward.h>
+#include <wtf/Vector.h>
 
-typedef const struct __CFData* CFDataRef;
-
 namespace WebCore {
 namespace DownloadBundle {
 
-bool appendResumeData(CFDataRef resumeData, const String& bundlePath);
-CFDataRef extractResumeData(const String& bundlePath);
+bool appendResumeData(const char*, uint32_t, const String& bundlePath);
+bool extractResumeData(const String& bundlePath, Vector<char>& resumeData);
 const String& fileExtension();
 
 } // namespace DownloadBundle

Modified: trunk/Source/WebCore/platform/network/win/DownloadBundleWin.cpp (153484 => 153485)


--- trunk/Source/WebCore/platform/network/win/DownloadBundleWin.cpp	2013-07-30 18:54:58 UTC (rev 153484)
+++ trunk/Source/WebCore/platform/network/win/DownloadBundleWin.cpp	2013-07-30 19:01:07 UTC (rev 153485)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "DownloadBundle.h"
 
-#include <CoreFoundation/CoreFoundation.h>
 #include <io.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -37,7 +36,7 @@
 
 namespace DownloadBundle {
 
-static UInt32 magicNumber()
+static uint32_t magicNumber()
 {
     return 0xDECAF4EA;
 }
@@ -48,9 +47,9 @@
     return extension;
 }
 
-bool appendResumeData(CFDataRef resumeData, const String& bundlePath)
+bool appendResumeData(const char* resumeBytes, uint32_t resumeLength, const String& bundlePath)
 {
-    if (!resumeData) {
+    if (!resumeBytes || !resumeLength) {
         LOG_ERROR("Invalid resume data to write to bundle path");
         return false;
     }
@@ -68,16 +67,6 @@
 
     bool result = false;
 
-    const UInt8* resumeBytes = CFDataGetBytePtr(resumeData);
-    ASSERT(resumeBytes);
-    if (!resumeBytes)
-        goto exit;
-
-    CFIndex resumeLength = CFDataGetLength(resumeData);
-    ASSERT(resumeLength > 0);
-    if (resumeLength < 1)
-        goto exit;
-
     if (fwrite(resumeBytes, 1, resumeLength, bundle) != resumeLength) {
         LOG_ERROR("Failed to write resume data to the bundle - errno(%i)", errno);
         goto exit;
@@ -88,7 +77,7 @@
         goto exit;
     }
 
-    const UInt32& magic = magicNumber();
+    const uint32_t magic = magicNumber();
     if (fwrite(&magic, 4, 1, bundle) != 1) {
         LOG_ERROR("Failed to write footer magic number to the bundle - errno(%i)", errno);
         goto exit;
@@ -100,11 +89,11 @@
     return result;
 }
 
-CFDataRef extractResumeData(const String& bundlePath)
+bool extractResumeData(const String& bundlePath, Vector<char>& resumeData)
 {
     if (bundlePath.isEmpty()) {
         LOG_ERROR("Cannot create resume data from empty download bundle path");
-        return 0;
+        return false;
     }
 
     // Open a handle to the bundle file
@@ -112,11 +101,10 @@
     FILE* bundle = 0;
     if (_wfopen_s(&bundle, nullifiedPath.charactersWithNullTermination().data(), TEXT("r+b")) || !bundle) {
         LOG_ERROR("Failed to open file %s to get resume data", bundlePath.ascii().data());
-        return 0;
+        return false;
     }
 
-    CFDataRef result = 0;
-    Vector<UInt8> footerBuffer;
+    bool result = false;
 
     // Stat the file to get its size
     struct _stat64 fileStat;
@@ -131,7 +119,7 @@
     if (fsetpos(bundle, &footerMagicNumberPosition))
         goto exit;
 
-    UInt32 footerMagicNumber = 0;
+    uint32_t footerMagicNumber = 0;
     if (fread(&footerMagicNumber, 4, 1, bundle) != 1) {
         LOG_ERROR("Failed to read footer magic number from the bundle - errno(%i)", errno);
         goto exit;
@@ -152,7 +140,7 @@
     if (fsetpos(bundle, &footerLengthPosition))
         goto exit;
 
-    UInt32 footerLength = 0;
+    uint32_t footerLength = 0;
     if (fread(&footerLength, 4, 1, bundle) != 1) {
         LOG_ERROR("Failed to read ResumeData length from the bundle - errno(%i)", errno);
         goto exit;
@@ -166,8 +154,8 @@
     if (fsetpos(bundle, &footerStartPosition))
         goto exit;
 
-    footerBuffer.resize(footerLength);
-    if (fread(footerBuffer.data(), 1, footerLength, bundle) != footerLength) {
+    resumeData.resize(footerLength);
+    if (fread(resumeData.data(), 1, footerLength, bundle) != footerLength) {
         LOG_ERROR("Failed to read ResumeData from the bundle - errno(%i)", errno);
         goto exit;
     }
@@ -181,11 +169,7 @@
         goto exit;
     }
 
-    // Finally, make the resume data.  Now, it is possible by some twist of fate the bundle magic number
-    // was naturally at the end of the file and its not actually a valid bundle.  That, or someone engineered
-    // it that way to try to attack us.  In that cause, this CFData will successfully create but when we 
-    // actually try to start the CFURLDownload using this bogus data, it will fail and we will handle that gracefully
-    result = CFDataCreate(0, footerBuffer.data(), footerLength);
+    result = true;
 exit:
     fclose(bundle);
     return result;

Modified: trunk/Source/WebKit/win/WebDownloadCFNet.cpp (153484 => 153485)


--- trunk/Source/WebKit/win/WebDownloadCFNet.cpp	2013-07-30 18:54:58 UTC (rev 153484)
+++ trunk/Source/WebKit/win/WebDownloadCFNet.cpp	2013-07-30 19:01:07 UTC (rev 153485)
@@ -166,11 +166,15 @@
 {
     LOG(Download, "Attempting resume of download bundle %s", String(bundlePath, SysStringLen(bundlePath)).ascii().data());
 
-    RetainPtr<CFDataRef> resumeData = adoptCF(DownloadBundle::extractResumeData(String(bundlePath, SysStringLen(bundlePath))));
-
-    if (!resumeData)
+    Vector<char> buffer;
+    if (!DownloadBundle::extractResumeData(String(bundlePath, SysStringLen(bundlePath)), buffer))
         return E_FAIL;
 
+    // It is possible by some twist of fate the bundle magic number was naturally at the end of the file and its not actually a valid bundle.
+    // That, or someone engineered it that way to try to attack us. In that cause, this CFData will successfully create but when we actually
+    // try to start the CFURLDownload using this bogus data, it will fail and we will handle that gracefully.
+    RetainPtr<CFDataRef> resumeData = adoptCF(CFDataCreate(0, reinterpret_cast<const UInt8*>(buffer.data()), buffer.size()));
+
     if (!delegate)
         return E_FAIL;
     m_delegate = delegate;
@@ -254,7 +258,9 @@
         goto exit;
     }
 
-    DownloadBundle::appendResumeData(resumeData.get(), m_bundlePath);
+    const char* resumeBytes = reinterpret_cast<const char*>(CFDataGetBytePtr(resumeData.get()));
+    uint32_t resumeLength = CFDataGetLength(resumeData.get());
+    DownloadBundle::appendResumeData(resumeBytes, resumeLength, m_bundlePath);
 
 exit:
     m_download = 0;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to