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

Commit 2e26d813 authored by Chong Zhang's avatar Chong Zhang
Browse files

Check actual read bytes for TS packets

Check actual bytes read when feeding the data to TS parser.

bug: 140177694
test: poc in bug; StreamingMediaPlayerTest

Change-Id: I4b498fe375af657e17838e5839e6348e1463d559
parent f5349568
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -130,21 +130,24 @@ void NuPlayer::StreamingSource::onReadBuffer() {
        } else if (n < 0) {
            break;
        } else {
            if (buffer[0] == 0x00) {
            if (buffer[0] == 0x00) { // OK to access buffer[0] since n must be > 0 here
                // XXX legacy

                if (extra == NULL) {
                    extra = new AMessage;
                }

                uint8_t type = buffer[1];
                uint8_t type = 0;
                if (n > 1) {
                    type = buffer[1];

                if (type & 2) {
                    if ((type & 2) && (n >= 2 + sizeof(int64_t))) {
                        int64_t mediaTimeUs;
                        memcpy(&mediaTimeUs, &buffer[2], sizeof(mediaTimeUs));

                        extra->setInt64(kATSParserKeyMediaTimeUs, mediaTimeUs);
                    }
                }

                mTSParser->signalDiscontinuity(
                        ((type & 1) == 0)
@@ -152,7 +155,7 @@ void NuPlayer::StreamingSource::onReadBuffer() {
                                : ATSParser::DISCONTINUITY_FORMATCHANGE,
                        extra);
            } else {
                status_t err = mTSParser->feedTSPacket(buffer, sizeof(buffer));
                status_t err = mTSParser->feedTSPacket(buffer, n);

                if (err != OK) {
                    ALOGE("TS Parser returned error %d", err);