From 0bb3986583a1daff2466c318473191d6cbd63adb Mon Sep 17 00:00:00 2001 From: Sergey Cherevko Date: Fri, 19 Jan 2024 16:35:06 +0300 Subject: [PATCH] Using libnatspec to correctly decode non-ASCII filenames zipped on Windows. --- CPP/7zip/Archive/Zip/ZipItem.cpp | 44 +++++++------------------------- makefile.linux_amd64_asm | 2 +- makefile.machine | 2 +- 3 files changed, 11 insertions(+), 37 deletions(-) diff --git a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp index 12bc8ad..16a4dbe 100644 --- a/CPP/7zip/Archive/Zip/ZipItem.cpp +++ b/CPP/7zip/Archive/Zip/ZipItem.cpp @@ -1,5 +1,5 @@ // Archive/ZipItem.cpp - +#include #include "StdAfx.h" #include "../../../../C/CpuArch.h" @@ -208,43 +208,17 @@ void CItem::GetUnicodeString(UString &res, const AString &s, bool isComment, boo bool isUtf8 = IsUtf8(); bool ignore_Utf8_Errors = true; - if (!isUtf8) - { - { - const unsigned id = isComment ? - NFileHeader::NExtraID::kIzUnicodeComment: - NFileHeader::NExtraID::kIzUnicodeName; - const CObjectVector &subBlocks = GetMainExtra().SubBlocks; - - FOR_VECTOR (i, subBlocks) - { - const CExtraSubBlock &sb = subBlocks[i]; - if (sb.ID == id) - { - AString utf; - if (sb.ExtractIzUnicode(CrcCalc(s, s.Len()), utf)) - if (ConvertUTF8ToUnicode(utf, res)) - return; - break; - } - } - } - - if (useSpecifiedCodePage) - isUtf8 = (codePage == CP_UTF8); - #ifdef _WIN32 - else if (GetHostOS() == NFileHeader::NHostOS::kUnix) - { - /* Some ZIP archives in Unix use UTF-8 encoding without Utf8 flag in header. - We try to get name as UTF-8. - Do we need to do it in POSIX version also? */ - isUtf8 = true; - ignore_Utf8_Errors = false; - } - #endif + if (!isUtf8) { + const char *oem_charset = natspec_get_charset_by_locale(NATSPEC_DOSCS, ""); + char *p = natspec_convert(s.Ptr(), NULL, oem_charset, 0); + AString utf = p; + free(p); + if (ConvertUTF8ToUnicode(utf, res)) + return; } + if (isUtf8) if (ConvertUTF8ToUnicode(s, res) || ignore_Utf8_Errors) return; diff --git a/makefile.linux_amd64_asm b/makefile.linux_amd64_asm index 075c6a8..3de8ccf 100644 --- a/makefile.linux_amd64_asm +++ b/makefile.linux_amd64_asm @@ -19,7 +19,7 @@ ASM=yasm -f elf -m amd64 -Dx64 PRE_COMPILED_HEADER=StdAfx.h.gch -LOCAL_LIBS=-lpthread +LOCAL_LIBS=-lpthread -lnatspec LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl CPU=x64 diff --git a/makefile.machine b/makefile.machine index 9e34c34..054edde 100644 --- a/makefile.machine +++ b/makefile.machine @@ -15,7 +15,7 @@ CC=gcc CC_SHARED=-fPIC LINK_SHARED=-fPIC -shared -LOCAL_LIBS=-lpthread +LOCAL_LIBS=-lpthread -lnatspec LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl OBJ_CRC32=$(OBJ_CRC32_C) -- 2.39.3