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

Commit 073a3d56 authored by Kenny Root's avatar Kenny Root
Browse files

Add better index checks for AndroidCharacter.mirror

Fix potential invalid array access if start index is before the
beginning of the array or start + count is past the end of the array.
Update Javadoc for mirror to reflect the usage of "start" and "count".

Change-Id: I7e596de8eae5c518a2b4ff0d28604bd9c59f9d9d
parent a4437fc9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -73,6 +73,11 @@ public class AndroidCharacter
     * Replace the specified slice of <code>text</code> with the chars'
     * right-to-left mirrors (if any), returning true if any
     * replacements were made.
     *
     * @param text array of characters to apply mirror operation
     * @param start first character in array to mirror
     * @param count maximum number of characters to mirror
     * @return true if replacements were made
     */
    public native static boolean mirror(char[] text, int start, int count);

+2 −1
Original line number Diff line number Diff line
@@ -165,7 +165,8 @@ static jboolean mirror(JNIEnv* env, jobject obj, jcharArray charArray, int start
        goto MIRROR_END;
    }

    if (start > start + count || env->GetArrayLength(charArray) < count) {
    if (start < 0 || start > start + count
            || env->GetArrayLength(charArray) < start + count) {
        jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", NULL);
        goto MIRROR_END;
    }