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]: Failed to open the output file: 拒绝访问。 #268

Open
1 task done
ywapple opened this issue Jan 7, 2025 · 4 comments
Open
1 task done

[Bug]: Failed to open the output file: 拒绝访问。 #268

ywapple opened this issue Jan 7, 2025 · 4 comments
Assignees
Labels

Comments

@ywapple
Copy link

ywapple commented Jan 7, 2025

2025010701104793692966-31994233647-20241201-20241231-09-430501040031335 (1).7z.zip

bit7z version

4.0.x

Compilation options

BIT7Z_7ZIP_VERSION, BIT7Z_AUTO_FORMAT, BIT7Z_PATH_SANITIZATION

7-zip version

v23.01

7-zip shared library used

7z.dll / 7z.so

Compilers

MSVC

Compiler versions

vs2022

Architecture

x86_64

Operating system

Windows

Operating system versions

win11

Bug description

The file decompression is abnormal
Failed to open the output file: Access denied.
But other compression software can decompress this file normally
Uploading 2025010701104793692966.7z…

Filename:2025010701104793692966-31994233647-20241201-20241231-09-430501040031335 (1).7z.zip
Due to the prohibition of uploading 7z format files, a. zip file was added to the file name
After downloading, please delete the. zip file in the file name for testing

Steps to reproduce

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

Expected behavior

No response

Relevant compilation output

No response

Code of Conduct

@rikyoz
Copy link
Owner

rikyoz commented Jan 7, 2025

Hi!

Failed to open the output file: Access denied.

Which folder are you extracting to?

But other compression software can decompress this file normally

Which compression software did you use?
Did you test the decompression with 7-Zip's GUI or CLI?

Uploading 2025010701104793692966.7z…

The file wasn't uploaded properly, I cannot download it for testing it.

@ywapple
Copy link
Author

ywapple commented Jan 8, 2025

Uploading 2025010701104793692966-31994233647-20241201-20241231-09-430501040031335 (1).7z.zip…

Hi!

Failed to open the output file: Access denied.

Which folder are you extracting to?

But other compression software can decompress this file normally

Which compression software did you use? Did you test the decompression with 7-Zip's GUI or CLI?

Uploading 2025010701104793692966.7z…

The file wasn't uploaded properly, I cannot download it for testing it.

I have already re uploaded the file
(Due to the prohibition of uploading 7z format files, a. zip file was added to the file name
After downloading, please delete the. zip file in the file name for testing)

@rikyoz
Copy link
Owner

rikyoz commented Jan 8, 2025

Thanks for the file, it really helped me figure out what is causing the problem!

The main problem is that the archive contains a file with a / leading character in the name.

Internally, bit7z uses std::filesystem::path to handle paths, and this considers a path with a leading / to be an absolute path. When combining the output directory path with an absolute path, std::filesystem::path simply ignores the output directory, and thus makes bit7z try to extract the file to the root directory (e.g. C:\); this fails due to insufficient permissions, and hence the "access denied".
I'll work on improving the handling of such edge cases, possibly in a next patch version or in the next v4.1-beta.

In the meantime, there's a possible workaround to correctly extract the file to the output directory, which is to disable preserving the directory structure of the archive:

BitFileExtractor extractor{ lib, BitFormat::Auto };
extractor.setRetainDirectories(false);
extractor.extract(zipFile, strOutDir.c_str());

@ywapple
Copy link
Author

ywapple commented Jan 9, 2025

Thanks for the file, it really helped me figure out what is causing the problem!

The main problem is that the archive contains a file with a leading character in the name./

Internally, bit7z uses to handle paths, and this considers a path with a leading to be an absolute path. When combining the output directory path with an absolute path, simply ignores the output directory, and thus makes bit7z try to extract the file to the root directory (e.g. ); this fails due to insufficient permissions, and hence the "access denied". I'll work on improving the handling of such edge cases, possibly in a next patch version or in the next v4.1-beta.std::filesystem::path``/``std::filesystem::path``C:\

In the meantime, there's a possible workaround to correctly extract the file to the output directory, which is to disable preserving the directory structure of the archive:

BitFileExtractor extractor{ lib, BitFormat::Auto };
extractor.setRetainDirectories(false);
extractor.extract(zipFile, strOutDir.c_str());

extractor.setRetainDirectories(false);
Using this feature will no longer meet the requirements.
Please fix and update it as soon as possible
Thank You!

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