From 8cca5892e5109cdfd500a43b69dd40653ff1667e Mon Sep 17 00:00:00 2001 From: Julian Raufelder Date: Thu, 18 Apr 2024 14:02:10 +0200 Subject: [PATCH] Fix upload of files >2GB to WebDAV Fixes #531 --- .../network/InputStreamSourceBasedRequestBody.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/data/src/main/java/org/cryptomator/data/cloud/webdav/network/InputStreamSourceBasedRequestBody.kt b/data/src/main/java/org/cryptomator/data/cloud/webdav/network/InputStreamSourceBasedRequestBody.kt index 51db86cff..202615641 100644 --- a/data/src/main/java/org/cryptomator/data/cloud/webdav/network/InputStreamSourceBasedRequestBody.kt +++ b/data/src/main/java/org/cryptomator/data/cloud/webdav/network/InputStreamSourceBasedRequestBody.kt @@ -13,7 +13,17 @@ internal class InputStreamSourceBasedRequestBody private constructor(private val @Throws(IOException::class) override fun contentLength(): Long { - return inputStream.available().toLong() + val availableBytes = inputStream.available() + /** + * inputStream.available() is an int and if the file to upload is > int.max it will overflow to 0. + * In this case we set contentLength to -1, which is fine, it just means the length is unknown. + * If inputStream.available() is actually 0, it does no harm either because we are not uploading a byte. + */ + return if (availableBytes != 0) { + availableBytes.toLong() + } else { + -1 + } } override fun contentType(): MediaType? {