From 67e38159f1b465c1b07da3bf407ad8558202d1ab Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Mon, 6 Apr 2020 14:28:27 +0900 Subject: [PATCH] Remove duplicated condition for checking the frame length Change-Id: I1be9feb05291cbd12719d8b7fef6270caf35a88c --- utils/mm_file_util_tag.c | 120 +++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/utils/mm_file_util_tag.c b/utils/mm_file_util_tag.c index 2532a36..9d11dd9 100644 --- a/utils/mm_file_util_tag.c +++ b/utils/mm_file_util_tag.c @@ -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); -- 2.7.4