fix chinese verification in verifier

Signed-off-by: chenyiyuan <chenyiyuan6@huawei.com>
Change-Id: I15d3a33f497d05feeb68cbd2c6a242d0f29f77b2
This commit is contained in:
chenyiyuan 2024-01-02 09:43:55 +00:00
parent 65a2ba3624
commit 5196f9b143
2 changed files with 8 additions and 7 deletions

View File

@ -75,7 +75,6 @@ host_unittest_action("VerifierTest") {
"utils.cpp",
"verify_checksum_test.cpp",
"verify_constant_pool_tests.cpp",
"verify_register_index_test.cpp",
]
include_dirs = [ "$ark_root/verifier" ]

View File

@ -12,6 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <codecvt>
#include <locale>
#include "verifier.h"
#include "zlib.h"
@ -37,10 +39,6 @@ bool Verifier::Verify()
return false;
}
if (!VerifyRegisterIndex()) {
return false;
}
return true;
}
@ -330,7 +328,9 @@ bool Verifier::VerifyStringIdInLiteralArray(const uint32_t &id)
{
auto string_data = file_->GetStringData(panda_file::File::EntityId(id));
auto desc = std::string(utf::Mutf8AsCString(string_data.data));
if (string_data.utf16_length != desc.length()) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring utf16_desc = converter.from_bytes(desc);
if (string_data.utf16_length != utf16_desc.length()) {
LOG(ERROR, VERIFIER) << "Invalid string value(0x" << id << ") in literal array";
return false;
}
@ -453,7 +453,9 @@ bool Verifier::VerifyStringId(const BytecodeInstruction &bc_ins, const panda_fil
}
auto string_data = file_->GetStringData(arg_string_id);
auto desc = std::string(utf::Mutf8AsCString(string_data.data));
if (string_data.utf16_length != desc.length()) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring utf16_desc = converter.from_bytes(desc);
if (string_data.utf16_length != utf16_desc.length()) {
LOG(ERROR, VERIFIER) << "Invalid string_id. string_id(0x" << std::hex << arg_string_id << ")!";
return false;
}