From 7d91551126f3af7022eced2e3fc514b8353170ea Mon Sep 17 00:00:00 2001 From: Kamil Bobrowski Date: Mon, 3 Aug 2020 21:53:55 +0200 Subject: [PATCH] reading from the stream in a loop this ensures that desired number of bytes will be read, as stream.read(byte[] buffer) will just make effort to read at least 1 byte --- .../ExposureNotificationServiceImpl.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureNotificationServiceImpl.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureNotificationServiceImpl.kt index b7610210..9bbda334 100644 --- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureNotificationServiceImpl.kt +++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureNotificationServiceImpl.kt @@ -159,7 +159,15 @@ class ExposureNotificationServiceImpl(private val context: Context, private val val entry = stream.nextEntry ?: break if (entry.name == "export.bin") { val prefix = ByteArray(16) - if (stream.read(prefix) == prefix.size && String(prefix).trim() == "EK Export v1") { + var totalBytesRead = 0 + var bytesRead = 0 + while (bytesRead != -1 && totalBytesRead < prefix.size) { + bytesRead = stream.read(prefix, totalBytesRead, prefix.size - totalBytesRead) + if (bytesRead > 0) { + totalBytesRead += bytesRead + } + } + if (totalBytesRead == prefix.size && String(prefix).trim() == "EK Export v1") { val fileKeys = storeDiagnosisKeyExport(params.token, TemporaryExposureKeyExport.ADAPTER.decode(stream)) keys + fileKeys } else {