You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/04/13 00:55:23 UTC

[james-project] branch 3.6.x updated: JAMES-3432 (pull request #374) to 3.6.x branch

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch 3.6.x
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/3.6.x by this push:
     new edf25ef  JAMES-3432 (pull request #374) to 3.6.x branch
edf25ef is described below

commit edf25ef584988ade4f4704fe378556871a78bb1b
Author: Juhan Aasaru <Ju...@nortal.com>
AuthorDate: Mon Apr 12 10:57:22 2021 +0300

    JAMES-3432 (pull request #374) to 3.6.x branch
---
 .../src/main/java/org/apache/james/jmap/http/UploadRoutes.java     | 7 ++++++-
 .../org/apache/james/jmap/rfc8621/contract/UploadContract.scala    | 4 ++--
 .../src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala | 6 +++++-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java
index 0311550..8e1f174 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java
@@ -30,6 +30,7 @@ import static org.apache.james.util.ReactorUtils.logOnError;
 
 import java.io.EOFException;
 import java.io.InputStream;
+import java.nio.ByteBuffer;
 import java.util.stream.Stream;
 
 import javax.inject.Inject;
@@ -114,7 +115,11 @@ public class UploadRoutes implements JMAPRoutes {
     }
 
     private Mono<Void> post(HttpServerRequest request, HttpServerResponse response, ContentType contentType, MailboxSession session) {
-        InputStream content = ReactorUtils.toInputStream(request.receive().asByteBuffer().subscribeOn(Schedulers.elastic()));
+        InputStream content = ReactorUtils.toInputStream(request.receive()
+            // Unwrapping to byte array needed to solve data races and buffer reordering when using .asByteBuffer()
+            .asByteArray()
+            .map(ByteBuffer::wrap)
+            .subscribeOn(Schedulers.elastic()));
         return Mono.from(metricFactory.decoratePublisherWithTimerMetric("JMAP-upload-post",
             handle(contentType, content, session, response)));
     }
diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/UploadContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/UploadContract.scala
index c28696d..f02de04 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/UploadContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/UploadContract.scala
@@ -33,7 +33,7 @@ import org.apache.james.jmap.rfc8621.contract.UploadContract.{BIG_INPUT_STREAM,
 import org.apache.james.utils.DataProbeImpl
 import org.assertj.core.api.Assertions.assertThat
 import org.hamcrest.Matchers.equalTo
-import org.junit.jupiter.api.{BeforeEach, Test}
+import org.junit.jupiter.api.{BeforeEach, RepeatedTest, Test}
 import play.api.libs.json.{JsString, Json}
 
 object UploadContract {
@@ -56,7 +56,7 @@ trait UploadContract {
       .build
   }
 
-  @Test
+  @RepeatedTest(50)
   def shouldUploadFileAndAllowToDownloadIt(): Unit = {
     val uploadResponse: String = `given`
       .basePath("")
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala
index 5617079..d863bf3 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.routes
 
 import java.io.InputStream
+import java.nio.ByteBuffer
 import java.nio.charset.StandardCharsets
 import java.util.stream
 import java.util.stream.Stream
@@ -137,7 +138,10 @@ class UploadRoutes @Inject()(@Named(InjectionKeys.RFC_8621) val authenticator: A
           .fold[SMono[Void]](
             e => SMono.raiseError(e),
             value => if (value) {
-              SMono.fromCallable(() => ReactorUtils.toInputStream(request.receive.asByteBuffer))
+              SMono.fromCallable(() => ReactorUtils.toInputStream(request.receive
+                // Unwrapping to byte array needed to solve data races and buffer reordering when using .asByteBuffer()
+                .asByteArray()
+                .map(array => ByteBuffer.wrap(array))))
               .flatMap(content => handle(targetAccountId, contentType, content, session, response))
             } else {
               SMono.raiseError(ForbiddenException())

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org