Remove duplicated condition for checking the frame length 58/229858/2
authorjiyong.min <jiyong.min@samsung.com>
Mon, 6 Apr 2020 05:28:27 +0000 (14:28 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 6 Apr 2020 05:35:43 +0000 (14:35 +0900)
Change-Id: I1be9feb05291cbd12719d8b7fef6270caf35a88c

utils/mm_file_util_tag.c

index 2532a36..9d11dd9 100644 (file)
@@ -3107,81 +3107,81 @@ bool mm_file_id3tag_parse_v222(AvFileContentInfo *pInfo, unsigned char *buffer)
                        while ((buffer[curPos - purelyFramelen + encodingOffSet] < 0x20) && (encodingOffSet < purelyFramelen))
                                encodingOffSet++;
 
-                       if (encodingOffSet < purelyFramelen) {
-                               realCpyFrameNum = purelyFramelen - encodingOffSet;
-                               mmfile_free(pExtContent);
-                               pExtContent = mmfile_malloc(realCpyFrameNum + 3);
-
-                               if (pExtContent == NULL) {
-                                       debug_error(DEBUG, "out of memory for pExtContent\n");
-                                       continue;
-                               }
-
-                               memset(pExtContent, '\0', realCpyFrameNum + 3);
+                       if (purelyFramelen - encodingOffSet <= 0) {
+                               debug_warning(DEBUG, "warning: wrong frame length\n");
+                               continue;
+                       }
 
-                               memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
+                       realCpyFrameNum = purelyFramelen - encodingOffSet;
+                       mmfile_free(pExtContent);
+                       pExtContent = mmfile_malloc(realCpyFrameNum + 3);
 
-                               if (realCpyFrameNum > 0) {
-                                       switch (tag_id) {
-                                       case AV_ID3TAG_COMMENT:
-                                               /*skip language data! */
-                                               if (realCpyFrameNum > 4) {
-                                                       realCpyFrameNum -= 4;
-                                                       tmp = 4;
+                       if (pExtContent == NULL) {
+                               debug_error(DEBUG, "out of memory for pExtContent\n");
+                               continue;
+                       }
 
-                                                       /*pExtContent[tmp+1] value should't have encoding value */
-                                                       if (pExtContent[tmp] > 0x20 && (pExtContent[tmp - 1] == 0x00 || pExtContent[tmp - 1] == 0x01)) {
-                                                               textEncodingType = __id3tag_get_text_encoding_v222(pExtContent, tmp);
-                                                               pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
-                                                               pInfo->tagInfo[tag_id].marked = true;
-                                                       } else {
-                                                               debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: failed to get Comment Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
-                                                       }
-                                               } else {
-                                                       debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: Description info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
-                                               }
-                                               break;
+                       memset(pExtContent, '\0', realCpyFrameNum + 3);
 
-                                       case AV_ID3TAG_URL:
-                                               if (realCpyFrameNum > 4) {
-                                                       /*skip language data! */
-                                                       realCpyFrameNum -= 4;
-                                                       tmp = 4;
+                       memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
 
-                                                       /*pExtContent[tmp+1] value should't have null value */
-                                                       if (pExtContent[tmp] > 0x20 && (pExtContent[tmp - 1] == 0x00 || pExtContent[tmp - 1] == 0x01)) {
-                                                               textEncodingType = __id3tag_get_text_encoding_v222(pExtContent, tmp);
+                       switch (tag_id) {
+                       case AV_ID3TAG_COMMENT:
+                               /*skip language data! */
+                               if (realCpyFrameNum > 4) {
+                                       realCpyFrameNum -= 4;
+                                       tmp = 4;
 
-                                                               pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
-                                                               pInfo->tagInfo[tag_id].marked = true;
-                                                       } else {
-                                                               debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: failed to get URL Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
-                                                       }
-                                               } else {
-                                                       debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: URL info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
-                                               }
-                                               break;
+                                       /*pExtContent[tmp+1] value should't have encoding value */
+                                       if (pExtContent[tmp] > 0x20 && (pExtContent[tmp - 1] == 0x00 || pExtContent[tmp - 1] == 0x01)) {
+                                               textEncodingType = __id3tag_get_text_encoding_v222(pExtContent, tmp);
+                                               pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
+                                               pInfo->tagInfo[tag_id].marked = true;
+                                       } else {
+                                               debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: failed to get Comment Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
+                                       }
+                               } else {
+                                       debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: Description info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
+                               }
+                               break;
 
+                       case AV_ID3TAG_URL:
+                               if (realCpyFrameNum > 4) {
+                                       /*skip language data! */
+                                       realCpyFrameNum -= 4;
+                                       tmp = 4;
 
-                                       case AV_ID3TAG_PICTURE:
-                                               if ((realCpyFrameNum <= 2000000) && _mm_file_id3tag_parse_PIC(pInfo, pExtContent, realCpyFrameNum, (const char*)charset_array[textEncodingType]))
-                                                               pInfo->tagInfo[tag_id].marked = true;
-                                               break;
+                                       /*pExtContent[tmp+1] value should't have null value */
+                                       if (pExtContent[tmp] > 0x20 && (pExtContent[tmp - 1] == 0x00 || pExtContent[tmp - 1] == 0x01)) {
+                                               textEncodingType = __id3tag_get_text_encoding_v222(pExtContent, tmp);
 
-                                       default:
                                                pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
                                                pInfo->tagInfo[tag_id].marked = true;
-
-                                               if (tag_id == AV_ID3TAG_GENRE)
-                                                       _mm_file_id3tag_add_bracket_at_genre(&pInfo->tagInfo[tag_id].value, pInfo->tagInfo[tag_id].length);
-                                               break;
+                                       } else {
+                                               debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: failed to get URL Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
                                        }
-
-                                       if (pInfo->tagInfo[tag_id].value)
-                                               debug_msg(RELEASE, "[%d] returned = (%s), len = (%d)\n", tag_id, pInfo->tagInfo[tag_id].value, pInfo->tagInfo[tag_id].length);
+                               } else {
+                                       debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: URL info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
                                }
+                               break;
+
 
+                       case AV_ID3TAG_PICTURE:
+                               if ((realCpyFrameNum <= 2000000) && _mm_file_id3tag_parse_PIC(pInfo, pExtContent, realCpyFrameNum, (const char*)charset_array[textEncodingType]))
+                                               pInfo->tagInfo[tag_id].marked = true;
+                               break;
+
+                       default:
+                               pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
+                               pInfo->tagInfo[tag_id].marked = true;
+
+                               if (tag_id == AV_ID3TAG_GENRE)
+                                       _mm_file_id3tag_add_bracket_at_genre(&pInfo->tagInfo[tag_id].value, pInfo->tagInfo[tag_id].length);
+                               break;
                        }
+
+                       if (pInfo->tagInfo[tag_id].value)
+                               debug_msg(RELEASE, "[%d] returned = (%s), len = (%d)\n", tag_id, pInfo->tagInfo[tag_id].value, pInfo->tagInfo[tag_id].length);
                }
 
                mmfile_free(pExtContent);