Add return value check in ID3v1 75/246875/7
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 5 Nov 2020 00:47:54 +0000 (09:47 +0900)
committerMinje ahn <minje.ahn@samsung.com>
Fri, 6 Nov 2020 03:25:51 +0000 (03:25 +0000)
If there is no tag value, an empty string or space character is returned.
Modify function to ignore this case.

Change-Id: I357e1f825699e2cd8e271f0c90e8462758cb96f1
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
utils/mm_file_util_tag.c

index 9617866..95d8347 100644 (file)
@@ -1537,7 +1537,7 @@ static int GetTagFromMetaBox(MMFileFormatContext *formatContext, MMFileIOHandle
                        mmfile_seek(fp, -(_ITUNES_READ_BUF_SZ - 1), SEEK_CUR);  /*FIXME: poor search*/
                } /*loop*/
 
-               /*ffmpeg extract artist, tracknum, excep cover image. see mov_read_udta_string()*/
+               /*ffmpeg extract artist, tracknum, except cover image. see mov_read_udta_string()*/
 #if 0
                if (artist_found) {
                        if (artist_sz > 0) {
@@ -1703,7 +1703,7 @@ static int GetTagFromMetaBox(MMFileFormatContext *formatContext, MMFileIOHandle
 
                        tagVersion = id3v2Box.id3v2Data[3];
                        if (tagVersion > 4) {
-                               debug_error(DEBUG, "tag vesion is too high");
+                               debug_error(DEBUG, "tag version is too high");
                                goto exception;
                        }
 
@@ -2407,7 +2407,7 @@ static bool __get_genre_num(const char *buffer, int *si)
        if (len > 6 || len == 0)
                return false;
 
-       /* Check fisrt c */
+       /* Check first c */
        if (len == 1) {
                if (!g_ascii_isdigit(buffer[0]))
                        return false;
@@ -2794,6 +2794,21 @@ static bool _mm_file_id3tag_parse_APIC(AvFileContentInfo *pInfo, unsigned char *
        return true;
 }
 
+static char * __id3tag_get_v110(const char *buf, ssize_t len, const char *locale)
+{
+       char *tmp_str = NULL;
+
+       mm_file_retv_if_fails(buf, NULL);
+       mm_file_retv_if_fails(locale, NULL);
+
+       tmp_str = mmfile_convert_to_utf8(buf, len, locale);
+
+       /* ID3v1 tag need check length or space. */
+       if (tmp_str && (strlen(tmp_str) == 0 || g_ascii_isspace(tmp_str[0])))
+               mmfile_free(tmp_str);
+
+       return tmp_str;
+}
 
 bool mm_file_id3tag_parse_v110(AvFileContentInfo *pInfo, unsigned char *buffer)
 {
@@ -2802,31 +2817,32 @@ bool mm_file_id3tag_parse_v110(AvFileContentInfo *pInfo, unsigned char *buffer)
        debug_msg(RELEASE, "ID3tag v110--------------------------------------------------------------");
 
        if (!pInfo->tagInfo[AV_ID3TAG_TITLE].value) {
-               pInfo->tagInfo[AV_ID3TAG_TITLE].value = mmfile_convert_to_utf8((const char *)&buffer[3], MP3_ID3_TITLE_LENGTH, locale);
+               pInfo->tagInfo[AV_ID3TAG_TITLE].value = __id3tag_get_v110((const char *)&buffer[3], MP3_ID3_TITLE_LENGTH, locale);
 
                debug_msg(RELEASE, "pInfo->pTitle returned =(%s)", pInfo->tagInfo[AV_ID3TAG_TITLE].value);
        }
 
        if (!pInfo->tagInfo[AV_ID3TAG_ARTIST].value) {
-               pInfo->tagInfo[AV_ID3TAG_ARTIST].value = mmfile_convert_to_utf8((const char *)&buffer[33], MP3_ID3_ARTIST_LENGTH, locale);
+               pInfo->tagInfo[AV_ID3TAG_ARTIST].value = __id3tag_get_v110((const char *)&buffer[33], MP3_ID3_ARTIST_LENGTH, locale);
 
                debug_msg(RELEASE, "pInfo->pArtist returned =(%s)", pInfo->tagInfo[AV_ID3TAG_ARTIST].value);
        }
 
        if (!pInfo->tagInfo[AV_ID3TAG_ALBUM].value) {
-               pInfo->tagInfo[AV_ID3TAG_ALBUM].value = mmfile_convert_to_utf8((const char *)&buffer[63], MP3_ID3_ALBUM_LENGTH, locale);
+               pInfo->tagInfo[AV_ID3TAG_ALBUM].value = __id3tag_get_v110((const char *)&buffer[63], MP3_ID3_ALBUM_LENGTH, locale);
 
                debug_msg(RELEASE, "pInfo->pAlbum returned =(%s)", pInfo->tagInfo[AV_ID3TAG_ALBUM].value);
        }
 
        if (!pInfo->tagInfo[AV_ID3TAG_YEAR].value) {
-               pInfo->tagInfo[AV_ID3TAG_YEAR].value = mmfile_convert_to_utf8((const char *)&buffer[93], MP3_ID3_YEAR_LENGTH, locale);
+               pInfo->tagInfo[AV_ID3TAG_YEAR].value = __id3tag_get_v110((const char *)&buffer[93], MP3_ID3_YEAR_LENGTH, locale);
 
                debug_msg(RELEASE, "pInfo->pYear returned =(%s)", pInfo->tagInfo[AV_ID3TAG_YEAR].value);
        }
 
        if (!pInfo->tagInfo[AV_ID3TAG_COMMENT].value) {
-               pInfo->tagInfo[AV_ID3TAG_COMMENT].value = mmfile_convert_to_utf8((const char *)&buffer[97], MP3_ID3_DESCRIPTION_LENGTH, locale);
+               pInfo->tagInfo[AV_ID3TAG_COMMENT].value = __id3tag_get_v110((const char *)&buffer[97], MP3_ID3_DESCRIPTION_LENGTH, locale);
+
                debug_msg(RELEASE, "pInfo->pComment returned =(%s)", pInfo->tagInfo[AV_ID3TAG_COMMENT].value);
        }
 
@@ -3122,7 +3138,7 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
 
                                if (textEncodingType != AV_ID3V2_UTF16 && textEncodingType != AV_ID3V2_UTF16_BE) {
                                        if (CompTmp[0] == 'T' || (strcmp(CompTmp, "APIC") == 0)) {
-                                               debug_msg(RELEASE, "get the new text ecoding type");
+                                               debug_msg(RELEASE, "get the new text encoding type");
                                                textEncodingType = buffer[curPos - purelyFramelen + encodingOffSet - 1];
                                        }
                                }
@@ -3381,7 +3397,7 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
 
                                if (textEncodingType != AV_ID3V2_UTF16 && textEncodingType != AV_ID3V2_UTF16_BE) {
                                        if (CompTmp[0] == 'T' || (strcmp(CompTmp, "APIC") == 0)) {
-                                               debug_msg(RELEASE, "get the new text ecoding type");
+                                               debug_msg(RELEASE, "get the new text encoding type");
                                                textEncodingType = buffer[curPos - purelyFramelen + encodingOffSet - 1];
                                        }
                                }