From: hj kim Date: Fri, 29 May 2020 05:14:32 +0000 (+0900) Subject: Check dynamic_cast result before using it X-Git-Tag: submit/tizen/20200602.021203~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8978a36b53d21f0cc84e4a27b09e9527c600ed0;p=platform%2Fcore%2Fapi%2Fmetadata-editor.git Check dynamic_cast result before using it Change-Id: I6b32ee6ce5e9202194dfe47add16a493ee442fa3 --- diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 69b798c..90af341 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -718,8 +718,9 @@ static int __metadata_editor_get_flac_metadata(metadata_editor_s *metadata, meta ret = __check_metadata_get_parameter(metadata, value); metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_get_parameter() [%d]", ret); - // Bring the pointer to actual file type and make tags pointers - auto _file = (FLAC::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->xiphComment(false); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); @@ -753,8 +754,9 @@ static int __metadata_editor_get_ogg_vorbis_metadata(metadata_editor_s *metadata ret = __check_metadata_get_parameter(metadata, value); metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_get_parameter() [%d]", ret); - // Bring the pointer to actual file type and make tags pointers - auto _file = (Ogg::Vorbis::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); @@ -787,8 +789,9 @@ static int __metadata_editor_get_ogg_flac_metadata(metadata_editor_s *metadata, ret = __check_metadata_get_parameter(metadata, value); metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_get_parameter() [%d]", ret); - // Bring the pointer to actual file type and make tags pointers - auto _file = (Ogg::FLAC::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); @@ -821,10 +824,10 @@ static int __metadata_editor_get_wav_metadata(metadata_editor_s *metadata, metad ret = __check_metadata_get_parameter(metadata, value); metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_get_parameter() [%d]", ret); - // Bring the pointer to actual file type and make tag pointers - auto _file = (RIFF::WAV::File*)metadata->file; - auto tag2 = _file->tag(); + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto tag2 = _file->tag(); if (tag2 == NULL) { // Check if we have a valid tag for processing metadata_editor_error("Error. ID3v2 tag does not exist. Can not proceed metadata extraction"); *value = NULL; @@ -940,8 +943,9 @@ static int __metadata_editor_set_flac_metadata(metadata_editor_s *metadata, meta ret = __check_metadata_set_parameter(metadata); metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_set_parameter() [%d]", ret); - // Bring the pointer to actual file type and make tags pointers - auto _file = (FLAC::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->xiphComment(true); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating"); @@ -973,8 +977,9 @@ static int __metadata_editor_set_ogg_vorbis_metadata(metadata_editor_s *metadata ret = __check_metadata_set_parameter(metadata); metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_set_parameter() [%d]", ret); - // Bring the pointer to actual file type and make tags pointers - auto _file = (Ogg::Vorbis::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating"); @@ -1006,8 +1011,9 @@ static int __metadata_editor_set_ogg_flac_metadata(metadata_editor_s *metadata, ret = __check_metadata_set_parameter(metadata); metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_set_parameter() [%d]", ret); - // Bring the pointer to actual file type and make tags pointers - auto _file = (Ogg::FLAC::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating"); @@ -1089,7 +1095,9 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) switch (_metadata->filetype) { case METADATA_EDITOR_FORMAT_MP3: { - auto _file = (MPEG::File*)_metadata->file; + auto _file = dynamic_cast(_metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto tag1 = _file->ID3v1Tag(); if (!tag1 || tag1->isEmpty()) { // If no ID3v1 tag - prevent its creation @@ -1174,7 +1182,10 @@ static int __get_APIC(ID3v2::Tag *tag, int index, void **picture, int *size, cha static int __get_mp3_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) { - return __get_APIC(dynamic_cast(metadata->file)->ID3v2Tag(), index, picture, size, mime_type); + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + + return __get_APIC(_file->ID3v2Tag(), index, picture, size, mime_type); } static int __get_mp4_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) @@ -1210,7 +1221,9 @@ static int __get_mp4_picture(metadata_editor_s *metadata, int index, void **pict #if 0 static int __get_flac_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) { - auto _file = (FLAC::File*) metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto lst = _file->pictureList(); if (lst.isEmpty()) { @@ -1238,7 +1251,8 @@ static int __get_flac_picture(metadata_editor_s *metadata, int index, void **pic static int __get_wav_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) { - auto _file = (RIFF::WAV::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); return __get_APIC(_file->tag(), index, picture, size, mime_type); } @@ -1322,7 +1336,9 @@ static int __append_mp4_picture(metadata_editor_s *metadata, const char *picture #if 0 static int __append_flac_picture(metadata_editor_s *metadata, const char *picture, size_t size, const char *mime_type) { - auto _file = (FLAC::File*) metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto frontCover = new FLAC::Picture; metadata_editor_debug_fenter(); @@ -1441,6 +1457,8 @@ static int __remove_mp4_picture(metadata_editor_s *metadata, int index) static int __remove_flac_picture(metadata_editor_s *metadata, int index) { auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto lst = _file->pictureList(); if (lst.isEmpty()) {