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

Commit 026b1a18 authored by Jake Hamby's avatar Jake Hamby Committed by android code review
Browse files

Merge "Telephony: Fix MT SMS with invalid TOA field causing crash issue"

parents f0414167 5ad6947b
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.internal.telephony.gsm;

import android.telephony.PhoneNumberUtils;

import java.text.ParseException;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.SmsAddress;

@@ -35,9 +35,10 @@ public class GsmSmsAddress extends SmsAddress {
     * @param offset the offset of the Address-Length byte
     * @param length the length in bytes rounded up, e.g. "2 +
     *        (addressLength + 1) / 2"
     * @throws ParseException
     */

    public GsmSmsAddress(byte[] data, int offset, int length) {
    public GsmSmsAddress(byte[] data, int offset, int length) throws ParseException {
        origBytes = new byte[length];
        System.arraycopy(data, offset, origBytes, 0, length);

@@ -49,7 +50,8 @@ public class GsmSmsAddress extends SmsAddress {

        // TOA must have its high bit set
        if ((toa & 0x80) != 0x80) {
            throw new RuntimeException("Invalid TOA - high bit must be set");
            throw new ParseException("Invalid TOA - high bit must be set. toa = " + toa,
                    offset + OFFSET_TOA);
        }

        if (isAlphanumeric()) {
+7 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.internal.telephony.SmsMessageBase;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;

import static com.android.internal.telephony.SmsConstants.MessageClass;
import static com.android.internal.telephony.SmsConstants.ENCODING_UNKNOWN;
@@ -560,7 +561,12 @@ public class SmsMessage extends SmsMessageBase {
            int addressLength = pdu[cur] & 0xff;
            int lengthBytes = 2 + (addressLength + 1) / 2;

            try {
                ret = new GsmSmsAddress(pdu, cur, lengthBytes);
            } catch (ParseException e) {
                Log.e(LOG_TAG, e.getMessage());
                ret = null;
            }

            cur += lengthBytes;