return true;
}
-static int __AvGetLastID3offset(MMFileIOHandle *fp, unsigned int *offset)
+static bool __AvGetID3Header(unsigned char *buf, size_t buf_size, AvTagVer2AdditionalData *id3v2info)
{
-#define _MMFILE_MP3_TAGV2_HEADER_LEN 10
-#define _MMFILE_GET_INT_NUMBER(buff) (int)((((int)(buff)[0]) << 24) | (((int)(buff)[1]) << 16) | (((int)(buff)[2]) << 8) | (((int)(buff)[3])))
+ if (!buf || buf_size < MP3_TAGv2_HEADER_LEN || !id3v2info) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return false;
+ }
+
+ if (!IS_ID3V2_TAG(buf)) {
+ debug_error(RELEASE, "Invalid ID3 identifier !");
+ return false;
+ }
- unsigned char tagHeader[_MMFILE_MP3_TAGV2_HEADER_LEN] = {0, };
- unsigned int tagInfoSize = 0;
- unsigned int acc_tagsize = 0;
- int tagVersion = 0;
- int encSize = 0;
- int readed = 0;
+ /* weak id3v2 tag check */
+ if (buf[3] == 0xFF || buf[4] == 0xFF || buf[6] >= 0x80 || buf[7] >= 0x80 || buf[8] >= 0x80 || buf[9] >= 0x80) {
+ debug_error(RELEASE, "Invalid ID3 base header!");
+ return false;
+ }
+
+ if (buf[3] > 0x04) {
+ debug_error(RELEASE, "Invalid or not supported ID3v2 version(%d)!", buf[3]);
+ return false;
+ }
+
+ id3v2info->tagVersion = buf[3];
+ id3v2info->tagLen = MP3_TAGv2_HEADER_LEN;
+ id3v2info->tagLen += (unsigned long)buf[6] << 21 | (unsigned long)buf[7] << 14 | (unsigned long)buf[8] << 7 | (unsigned long)buf[9];
+ debug_msg(RELEASE, "ID3v2 version(%d), length (%d)\n", id3v2info->tagVersion, id3v2info->tagLen);
+
+ return true;
+}
+
+static int __AvGetLastID3offset(MMFileIOHandle *fp, unsigned int *offset)
+{
+ unsigned char tagHeader[MP3_TAGv2_HEADER_LEN] = {0, };
+ unsigned int total_taglen = 0;
+ int read = 0;
+ AvTagVer2AdditionalData tagInfo = { 0, };
/*init offset*/
*offset = 0;
_START_TAG_SEARCH:
- readed = mmfile_read(fp, tagHeader, _MMFILE_MP3_TAGV2_HEADER_LEN);
- if (readed != _MMFILE_MP3_TAGV2_HEADER_LEN) {
+ read = mmfile_read(fp, tagHeader, MP3_TAGv2_HEADER_LEN);
+ if (read != MP3_TAGv2_HEADER_LEN) {
debug_error(DEBUG, "read error occured.\n");
return 0;
}
- if (memcmp(tagHeader, "ID3", 3) == 0) {
- debug_msg(RELEASE, "'ID3' found.\n");
- } else {
- debug_msg(RELEASE, "'ID3' not found.\n");
- goto search_end;
- }
-
- /**@note weak id3v2 tag checking*/
- if (tagHeader[3] != 0xFF && tagHeader[4] != 0xFF &&
- (tagHeader[6] & 0x80) == 0 && (tagHeader[7] & 0x80) == 0 &&
- (tagHeader[8] & 0x80) == 0 && (tagHeader[9] & 0x80) == 0) {
- debug_msg(RELEASE, "good ID3V2 tag.\n");
- } else {
- debug_warning(DEBUG, "It's bad ID3V2 tag.\n");
- goto search_end;
- }
-
- tagVersion = tagHeader[3];
-
- if (tagVersion > 4) {
- debug_msg(RELEASE, "Tag version not supported\n");
+ if (!__AvGetID3Header(tagHeader, MP3_TAGv2_HEADER_LEN, &tagInfo)) {
+ debug_msg(RELEASE, "Invalid ID3 header\n");
goto search_end;
}
- encSize = _MMFILE_GET_INT_NUMBER(&tagHeader[6]);
- tagInfoSize = _MMFILE_MP3_TAGV2_HEADER_LEN;
- tagInfoSize += (((encSize & 0x0000007F) >> 0) | ((encSize & 0x00007F00) >> 1) | ((encSize & 0x007F0000) >> 2) | ((encSize & 0x7F000000) >> 3));
-
/**@note unfortunately, some contents has many id3 tag.*/
- acc_tagsize += tagInfoSize;
- debug_msg(RELEASE, "tag size: %u, offset: %u\n", tagInfoSize, acc_tagsize);
+ total_taglen += tagInfo.tagLen;
+ debug_msg(RELEASE, "tag size: %u, offset: %u\n", tagInfo.tagLen, total_taglen);
- mmfile_seek(fp, acc_tagsize, MMFILE_SEEK_SET);
- *offset = acc_tagsize;
+ mmfile_seek(fp, total_taglen, MMFILE_SEEK_SET);
+ *offset = total_taglen;
goto _START_TAG_SEARCH;
search_end:
return 1;
}
-
-
/*
* This fuction retrieves the start position of header.
* Param _pFile [in] Specifies the file pointer of mp3 file.
}
if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) > 0) {
- if (IS_ID3V2_TAG(v2TagExistCheck)) {
- if (!(v2TagExistCheck[3] == 0xFF || v2TagExistCheck[4] == 0xFF || v2TagExistCheck[6] >= 0x80 || v2TagExistCheck[7] >= 0x80 || v2TagExistCheck[8] >= 0x80 || v2TagExistCheck[9] >= 0x80)) {
- if (!(v2TagExistCheck[3] > 0x04)) {
- pInfo->tagV2Info.tagVersion = v2TagExistCheck[3];
- pInfo->tagV2Info.tagLen = MP3_TAGv2_HEADER_LEN;
- pInfo->tagV2Info.tagLen += (unsigned long)v2TagExistCheck[6] << 21 | (unsigned long)v2TagExistCheck[7] << 14 | (unsigned long)v2TagExistCheck[8] << 7 | (unsigned long)v2TagExistCheck[9];
- debug_msg(RELEASE, "pInfo->tagV2Info.tagLen(%d), pInfo->tagV2Info.tagVersion(%d)\n", pInfo->tagV2Info.tagLen, pInfo->tagV2Info.tagVersion);
- } else {
- debug_msg(RELEASE, "tag is a not supported version(%d)\n", v2TagExistCheck[3]);
- }
- } else {
- debug_msg(RELEASE, "tag is a tag data is valid.\n");
- }
- } else {
- debug_msg(RELEASE, "this mp3 file is not included ID3v2 tag info!\n");
- }
+ __AvGetID3Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
+ mmfile_free(v2TagExistCheck);
} else {
debug_error(DEBUG, "v2TagExistCheck value read fail!\n");
mmfile_free(v2TagExistCheck);
goto EXCEPTION;
}
- mmfile_free(v2TagExistCheck);
-
- if (!(pInfo->fileLen > pInfo->tagV2Info.tagLen))
+ if (pInfo->fileLen < pInfo->tagV2Info.tagLen)
pInfo->tagV2Info.tagLen = 0;
if (mmfile_seek(hFile, 0L, SEEK_SET) < 0)