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

Commit c54432ae authored by Ray Essick's avatar Ray Essick
Browse files

Better handling of empty ID3 tags

Watch for 0 length ID3 tags, avoiding allocations of 0 bytes when
we see these.  Change code around "new" invocations so that we won't
throw exceptions and we check for null returns when they do fail.

Bug: 30744884
parent c964d478
Loading
Loading
Loading
Loading
+28 −15
Original line number Diff line number Diff line
@@ -77,7 +77,10 @@ ID3::ID3(const uint8_t *data, size_t size, bool ignoreV1)
      mFirstFrameOffset(0),
      mVersion(ID3_UNKNOWN),
      mRawSize(0) {
    sp<MemorySource> source = new MemorySource(data, size);
    sp<MemorySource> source = new (std::nothrow) MemorySource(data, size);

    if (source == NULL)
        return;

    mIsValid = parseV2(source, 0);

@@ -555,11 +558,15 @@ void ID3::Iterator::getstring(String8 *id, bool otherdata) const {
        const char16_t *framedata = (const char16_t *) (frameData + 1);
        char16_t *framedatacopy = NULL;
#if BYTE_ORDER == LITTLE_ENDIAN
        framedatacopy = new char16_t[len];
        if (len > 0) {
            framedatacopy = new (std::nothrow) char16_t[len];
            if (framedatacopy != NULL) {
                for (int i = 0; i < len; i++) {
                    framedatacopy[i] = bswap_16(framedata[i]);
                }
                framedata = framedatacopy;
            }
        }
#endif
        id->setTo(framedata, len);
        if (framedatacopy != NULL) {
@@ -573,12 +580,16 @@ void ID3::Iterator::getstring(String8 *id, bool otherdata) const {
        char16_t *framedatacopy = NULL;
        if (*framedata == 0xfffe) {
            // endianness marker doesn't match host endianness, convert
            framedatacopy = new char16_t[len];
            if (len > 0) {
                framedatacopy = new (std::nothrow) char16_t[len];
                if (framedatacopy != NULL) {
                    for (int i = 0; i < len; i++) {
                        framedatacopy[i] = bswap_16(framedata[i]);
                    }
                    framedata = framedatacopy;
                }
            }
        }
        // If the string starts with an endianness marker, skip it
        if (*framedata == 0xfeff) {
            framedata++;
@@ -593,14 +604,16 @@ void ID3::Iterator::getstring(String8 *id, bool otherdata) const {
                break;
            }
        }
        if (eightBit) {
        if (eightBit && len > 0) {
            // collapse to 8 bit, then let the media scanner client figure out the real encoding
            char *frame8 = new char[len];
            char *frame8 = new (std::nothrow) char[len];
            if (frame8 != NULL) {
                for (int i = 0; i < len; i++) {
                    frame8[i] = framedata[i];
                }
                id->setTo(frame8, len);
                delete [] frame8;
            }
        } else {
            id->setTo(framedata, len);
        }