From 1ca13d8c566ae71455cccc71efcdc8227e5a4a31 Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Thu, 23 May 2024 00:40:16 +0200 Subject: [PATCH] Fixed some minor errors: 1) Avoid possible problems with table size calculation 2) Assume CP437 if charset detection fails --- CPP/7zip/Archive/Zip/ZipItem.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp index 4102abb5..4454c620 100644 --- a/CPP/7zip/Archive/Zip/ZipItem.cpp +++ b/CPP/7zip/Archive/Zip/ZipItem.cpp @@ -448,7 +448,12 @@ void CItem::GetUnicodeString(UString &res, const AString &s, bool isComment, boo if (isOem || isAnsi) { const char *legacyCp = nullptr; - int tableLen = sizeof(isOem ? lcToOemTable : lcToAnsiTable) / sizeof(char *); + int tableLen; + if (isOem) { + tableLen = sizeof(lcToOemTable) / sizeof(lcToOemTable[0]); + } else { + tableLen = sizeof(lcToAnsiTable) / sizeof(lcToAnsiTable[0]); + } int lcLen = 0, i; // Detect required code page name from current locale @@ -465,6 +470,11 @@ void CItem::GetUnicodeString(UString &res, const AString &s, bool isComment, boo } } + // not found; use 437 by default + if (!legacyCp) { + legacyCp = "CP437"; + } + if (legacyCp) { iconv_t cd; if ((cd = iconv_open("UTF-8", legacyCp)) != (iconv_t)-1) {