Title: [270998] trunk/Source/WebKit
Revision
270998
Author
beid...@apple.com
Date
2020-12-18 17:02:47 -0800 (Fri, 18 Dec 2020)

Log Message

Fix some issues with PDFs as <object>.
https://bugs.webkit.org/show_bug.cgi?id=220024

Reviewed by Tim Horton.

No new tests (Unable to write automated tests)

* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::dataProviderGetBytesAtPositionCallback):
(WebKit::PDFPlugin::getResourceBytesAtPosition): Set the correct URL.
(WebKit::PDFPlugin::ByteRangeRequest::completeWithAccumulatedData): Try harder to catch mismatches in delivered bytes vs expected bytes.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (270997 => 270998)


--- trunk/Source/WebKit/ChangeLog	2020-12-19 00:39:20 UTC (rev 270997)
+++ trunk/Source/WebKit/ChangeLog	2020-12-19 01:02:47 UTC (rev 270998)
@@ -1,3 +1,17 @@
+2020-12-18  Brady Eidson  <beid...@apple.com>
+
+        Fix some issues with PDFs as <object>.
+        https://bugs.webkit.org/show_bug.cgi?id=220024
+
+        Reviewed by Tim Horton.
+
+        No new tests (Unable to write automated tests)
+
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::dataProviderGetBytesAtPositionCallback):
+        (WebKit::PDFPlugin::getResourceBytesAtPosition): Set the correct URL.
+        (WebKit::PDFPlugin::ByteRangeRequest::completeWithAccumulatedData): Try harder to catch mismatches in delivered bytes vs expected bytes.
+
 2020-12-18  Jeff Miller  <je...@apple.com>
 
         WKProcessPool enhancements for URL schemes

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (270997 => 270998)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-12-19 00:39:20 UTC (rev 270997)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-12-19 01:02:47 UTC (rev 270998)
@@ -785,7 +785,7 @@
 
     RunLoop::main().dispatch([plugin = WTFMove(plugin), position, count, buffer, &dataSemaphore, &bytesProvided] {
         plugin->getResourceBytesAtPosition(count, position, [count, buffer, &dataSemaphore, &bytesProvided](const uint8_t* bytes, size_t bytesCount) {
-            ASSERT_UNUSED(count, bytesCount <= count);
+            RELEASE_ASSERT(bytesCount <= count);
             memcpy(buffer, bytes, bytesCount);
             bytesProvided = bytesCount;
             dataSemaphore.signal();
@@ -974,6 +974,7 @@
         return;
 
     auto resourceRequest = documentLoader->request();
+    resourceRequest.setURL(m_sourceURL);
     resourceRequest.setHTTPHeaderField(HTTPHeaderName::Range, makeString("bytes="_s, position, "-"_s, position + count - 1));
     resourceRequest.setCachePolicy(ResourceRequestCachePolicy::DoNotUseAnyCache);
 
@@ -1054,8 +1055,14 @@
     plugin.pdfLog(makeString("Completing range request ", identifier()," (", m_count," bytes at ", m_position,") with ", m_accumulatedData.size()," bytes from the network"));
 #endif
 
-    m_completionHandler(m_accumulatedData.data(), m_accumulatedData.size());
+    auto completionSize = m_accumulatedData.size();
+    if (completionSize > m_count) {
+        RELEASE_LOG_ERROR(IncrementalPDF, "PDF byte range request got more bytes back from the server than requested. This is likely due to a misconfigured server. Capping result at the requested number of bytes.");
+        completionSize = m_count;
+    }
 
+    m_completionHandler(m_accumulatedData.data(), completionSize);
+
     // Fold this data into the main data buffer so that if something in its range is requested again (which happens quite often)
     // we do not need to hit the network layer again.
     plugin.ensureDataBufferLength(m_position + m_accumulatedData.size());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to