Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 535ec616 authored by Christoph Studer's avatar Christoph Studer
Browse files

Notification: Limit length of accepted strings

Limit strings to 5K in order to prevent apps from spamming the system
with overly long strings.

Bug: 17363929
Bug: 16151806
Change-Id: Id41e3fcc1ae1bc8ac8dd41d5059c2cc42f86f017
parent 192ba20d
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -128,6 +128,14 @@ public class Notification implements Parcelable

    public static final int DEFAULT_LIGHTS = 4;

    /**
     * Maximum length of CharSequences accepted by Builder and friends.
     *
     * <p>
     * Avoids spamming the system with overly large strings such as full e-mails.
     */
    private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024;

    /**
     * A timestamp related to this notification, in milliseconds since the epoch.
     *
@@ -1434,6 +1442,10 @@ public class Notification implements Parcelable
     * @hide
     */
    public static CharSequence safeCharSequence(CharSequence cs) {
        if (cs == null) return cs;
        if (cs.length() > MAX_CHARSEQUENCE_LENGTH) {
            cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH);
        }
        if (cs instanceof Parcelable) {
            Log.e(TAG, "warning: " + cs.getClass().getCanonicalName()
                    + " instance is a custom Parcelable and not allowed in Notification");