Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: tar File decompression failed #257

Open
1 task done
ywapple opened this issue Oct 28, 2024 · 1 comment
Open
1 task done

[Bug]: tar File decompression failed #257

ywapple opened this issue Oct 28, 2024 · 1 comment
Assignees
Labels

Comments

@ywapple
Copy link

ywapple commented Oct 28, 2024

bit7z version

4.0.x, 3.2.x

Compilation options

BIT7Z_AUTO_FORMAT

7-zip version

v23.01

7-zip shared library used

7z.dll / 7z.so

Compilers

MSVC

Compiler versions

vs2022

Architecture

x86

Operating system

Windows

Operating system versions

No response

Bug description

The read content is as follows:

\颜色分类:奶茶色;镜片折射率:镜框+【微薄】1.56防蓝光防辐射镜片(适合0-300度)_椰妇_2023年08月05日_初评.txt
\颜色分类:奶茶色;镜片折射率:镜框+【微薄】1.56防蓝光防辐射镜片(适合0-300度)_椰
妇_2023年08月05日_初评图片_1.jpg
\颜色分类:奶茶色;镜片折射率:镜框+【微薄】1.56防蓝光防辐射镜片(适合0-300度)_椰妇_2023年08月05日_初评图片_2.jpg
\颜色分类:奶茶色;镜片折射率:镜框+【微薄】1.56防蓝光防辐射镜片(适合0-300度)_椰
妇_2023年08月05日_初评图片_3.jpg
\颜色分类:奶茶色;镜片折射率:镜框+【微薄】1.56防蓝光防辐射镜片(适合0-300度)_椰***妇_2023年08月05日_初评图片_4.jpg

BitFileExtractor extractor{ lib, BitFormat::Auto };
Exception: Failed to open the output file: 文件名、目录名或卷标语法不正确。

Steps to reproduce

bool UnzipTest(const wstring& zipFile, const wstring& strOutDir)
{
try
{
Bit7zLibrary lib;
BitFileExtractor extractor{ lib, BitFormat::Auto };
}
catch (const bit7z::BitException& ex)
{
auto msg = ex.what();
auto code = ex.nativeCode();
auto posixCode = ex.posixCode();
return false;
}
return true;
}

UnzipTest(L"D:\tar\123.tar", L"C:\tar\123");

Expected behavior

Correctly UnZip files Suc

The 123.rar file extracted from 123.zip in the attachment is the file I tested

123.zip

Relevant compilation output

No response

Code of Conduct

@rikyoz
Copy link
Owner

rikyoz commented Oct 28, 2024

Hi!

I think your code example is missing the line where you actually call the extract method of BitFileExtractor.

Anyway, your problem is that the files in the tar/zip archive have an invalid character in their names, specifically the character :, hence the error. On Windows, files and folders cannot contain such a character (as explained here).

You can enable the bit7z option BIT7Z_PATH_SANITIZATION: in this case bit7z will take care of replacing all invalid characters in the file names with the underscore character _.

Also, since the paths of the files are absolute paths, bit7z will try to extract them to the disk root directory (e.g., C:\) rather than to the output path you pass to the method.
This is likely to fail unless you run the program with admin privileges.
You can avoid the latter problem by calling extractor.setRetainDirectories( false ); before extracting the archive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants