tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 46256293710f2955536a86dd730a8b1eddda939c
parent acf908c87ccd46fad92e3d36a419287716b3f8a3
Author: Markus Stange <mstange.moz@gmail.com>
Date:   Fri,  5 Dec 2025 00:16:22 +0000

Bug 2003945 - Call Charset.forName with "UTF-8" if "charset=" is not present in the contentType. r=android-reviewers,nalexander

If the substring is not present, then by default, substringAfter returns the
entire original string. So for a contentType of "image/jpeg" we would
call `Charset.forName("image/jpeg")`. This sends the Charset internals
down a slow path where we end up iterating over the ClassLoader resources
and decoding the apk zip file members.

Profiles:
Before: https://share.firefox.dev/49WuRYW (27 samples in RustHttpConfig.doFetch)
After: https://share.firefox.dev/445MBNV (7 samples in RustHttpConfig.doFetch)

Differential Revision: https://phabricator.services.mozilla.com/D275015

Diffstat:
Mmobile/android/android-components/components/concept/fetch/src/main/java/mozilla/components/concept/fetch/Response.kt | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mobile/android/android-components/components/concept/fetch/src/main/java/mozilla/components/concept/fetch/Response.kt b/mobile/android/android-components/components/concept/fetch/src/main/java/mozilla/components/concept/fetch/Response.kt @@ -61,7 +61,7 @@ data class Response( @Suppress("TooGenericExceptionCaught") private val charset = contentType?.let { - val charset = it.substringAfter("charset=") + val charset = it.substringAfter("charset=", "UTF-8") try { Charset.forName(charset) } catch (e: Exception) {