Skip to content

[Bug]: deal with UTF-16(with surrogate pair) file error #276

Description

@debugee

bit7z version

4.0.8

Compilation options

No response

7-zip version

v24.09

7-zip shared library used

lib7zip.dylib

Compilers

Clang

Compiler versions

No response

Architecture

x86_64

Operating system

macOS

Operating system versions

No response

Bug description

item.name throw Exception on macOS

    for (const auto &item : arc)
    {
        std::cout << std::endl;
        std::cout << "  Item index: " << item.index() << std::endl;
        std::cout << "    Name: " << item.name() << std::endl;
        std::cout << "    Extension: " << item.extension() << std::endl;
        std::cout << "    Path: " << item.path() << std::endl;
        std::cout << "    IsDir: " << item.isDir() << std::endl;
        std::cout << "    Size: " << item.size() << std::endl;
        std::cout << "    Packed size: " << item.packSize() << std::endl;
        std::cout << "    CRC: " << std::hex << item.crc() << std::dec << std::endl;
    }


        //7zip return utf-16 string by CHandler::GetProperty(CPP/7zip/Archive/Zip/ZipHandler.cpp)
        //return UString contain double wchar_t discrip the surrogate pair utf-16 char
        //if windows, this is right for utf-16 string
        //is other os, this is difference with wchar_t * (one dword discrip one unicode char)
        //7zz intelnal use UString(double wchar_t discrip one unicode char) transfer back use function CStdOutStream::Convert_UString_to_AString,when cout
        //so 7zz have no error with this
        //but bit7z use BitPropVariant::getNativeString() (src/bitpropvariant.cpp) (contain double wchar_t discrip one unicode char) to get UString from 7z
        //and bit7z::narrow transfer UString to std::string, it will cause error
        //so item.name() throw Exception: wstring_convert: to_bytes error

Steps to reproduce

on macOS

git clone https://github.com/debugee/bit7zip-test.git

cd bit7zip-test

cmake -B build .

cmake --build build --target install

./build/test ./😊123你好.zip

./😊123你好.zip
Processing archive: ./😊123你好.zip
Archive properties
Items count: 2
Folders count: 0
Files count: 2
Size: 220
Packed size: 92

Archived items
Item index: 0
Name: Exception: wstring_convert: to_bytes error

Expected behavior

No response

Relevant compilation output

Code of Conduct

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions