Bug 1545039 - Correctly copy request bodies in GeckoWebExecutor r=geckoview-reviewers,agi
authorJames Willcox <snorp@snorp.net>
Thu, 18 Apr 2019 19:56:30 +0000
changeset 470135 729b68c38f9f78f2438f1495efb4c3f246466357
parent 470134 8c2c3afe6a3d8b0d32c77aef1c1ca718326632b0
child 470136 22c00a19e267d91446352bff4d39d70a1280b20c
push id35888
push useraiakab@mozilla.com
push dateFri, 19 Apr 2019 09:47:45 +0000
treeherdermozilla-central@0160424142d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, agi
bugs1545039
milestone68.0a1
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 1545039 - Correctly copy request bodies in GeckoWebExecutor r=geckoview-reviewers,agi Differential Revision: https://phabricator.services.mozilla.com/D28095
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebExecutorTest.kt
widget/android/WebExecutorSupport.cpp
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebExecutorTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebExecutorTest.kt
@@ -39,16 +39,17 @@ import org.mozilla.geckoview.GeckoWebExe
 import org.mozilla.geckoview.WebRequest
 import org.mozilla.geckoview.WebRequestError
 import org.mozilla.geckoview.WebResponse
 
 import org.mozilla.geckoview.test.util.Environment
 import org.mozilla.geckoview.test.util.HttpBin
 import org.mozilla.geckoview.test.util.RuntimeCreator
 import java.net.UnknownHostException
+import java.util.*
 
 @MediumTest
 @RunWith(AndroidJUnit4::class)
 class WebExecutorTest {
     companion object {
         val TEST_ENDPOINT: String = "http://localhost:4242"
     }
 
@@ -101,20 +102,32 @@ class WebExecutorTest {
     }
 
     fun WebResponse.getJSONBody(): JSONObject {
         val bytes = this.getBodyBytes()
         val bodyString = Charset.forName("UTF-8").decode(bytes).toString()
         return JSONObject(bodyString)
     }
 
+    private fun randomString(count: Int): String {
+        val chars = "01234567890abcdefghijklmnopqrstuvwxyz[],./?;'"
+        val builder = StringBuilder(count)
+        val rand = Random(System.currentTimeMillis())
+
+        for (i in 0 until count) {
+            builder.append(chars[rand.nextInt(chars.length)])
+        }
+
+        return builder.toString()
+    }
+
     @Test
     fun smoke() {
         val uri = "$TEST_ENDPOINT/anything"
-        val bodyString = "This is the POST data"
+        val bodyString = randomString(8192)
         val referrer = "http://foo/bar"
 
         val request = WebRequest.Builder(uri)
                 .method("POST")
                 .header("Header1", "Clobbered")
                 .header("Header1", "Value")
                 .addHeader("Header2", "Value1")
                 .addHeader("Header2", "Value2")
--- a/widget/android/WebExecutorSupport.cpp
+++ b/widget/android/WebExecutorSupport.cpp
@@ -82,17 +82,17 @@ class ByteBufferStream final : public ns
     if (mClosed) {
       return NS_BASE_STREAM_CLOSED;
     }
 
     *aCountRead = uint32_t(
         std::min(uint64_t(mBuffer->Capacity() - mPosition), uint64_t(aCount)));
 
     if (*aCountRead > 0) {
-      memcpy(aBuf, (char*)mBuffer->Address(), *aCountRead);
+      memcpy(aBuf, (char*)mBuffer->Address() + mPosition, *aCountRead);
       mPosition += *aCountRead;
     }
 
     return NS_OK;
   }
 
   NS_IMETHOD
   ReadSegments(nsWriteSegmentFun aWriter, void* aClosure, uint32_t aCount,