From 1802a2b7f1abb50cdfc9bd28a97ffda7b5e3863b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 23 Sep 2024 09:11:39 +0200 Subject: [PATCH] Avoid crash (OOM) when content is too long. --- .../network/interceptors/FormattedJsonHttpLogger.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/network/src/main/kotlin/io/element/android/libraries/network/interceptors/FormattedJsonHttpLogger.kt b/libraries/network/src/main/kotlin/io/element/android/libraries/network/interceptors/FormattedJsonHttpLogger.kt index 7a87babb69..9b984d6613 100644 --- a/libraries/network/src/main/kotlin/io/element/android/libraries/network/interceptors/FormattedJsonHttpLogger.kt +++ b/libraries/network/src/main/kotlin/io/element/android/libraries/network/interceptors/FormattedJsonHttpLogger.kt @@ -34,6 +34,11 @@ internal class FormattedJsonHttpLogger( // It can be only the case if we log the bodies of Http requests. if (level != HttpLoggingInterceptor.Level.BODY) return + if (message.length > 100_000) { + Timber.d("Content is too long (${message.length} chars) to be formatted as JSON") + return + } + if (message.startsWith("{")) { // JSON Detected try {