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

zip_open fails with error 18 when file path contains umlauts #68

Closed
ZockerFloh7 opened this issue Oct 11, 2018 · 6 comments
Closed

zip_open fails with error 18 when file path contains umlauts #68

ZockerFloh7 opened this issue Oct 11, 2018 · 6 comments

Comments

@ZockerFloh7
Copy link

Dear authors of libzip,

first of all I want to thank you for your great zip library.
It was easy to implement and is much better in usage and performance than wxZip.

I write you because I have found a small issue.
When I try to open zip files using the zip_open function I get an error in some cases.
The function returns error code 18 when I try to open a zip with a file path containing umlauts.

#define ZIP_ER_INVAL 18 /* N Invalid argument */

Can you please tell me what I can do, to fix this issue?
I cannot prevent my users from opening zips where the file path contains umlauts.

Yours Sincerely

@dillof
Copy link
Member

dillof commented Oct 11, 2018

On wich operating system are you using libzip?

Can you trace through zip_open to see where the error occurs?

@ZockerFloh7
Copy link
Author

Hey, thanks for your fast reply.
I am using Windows 7 Professional x64 with libzip 1.5.1.

This is the path that gets passed to the function:

C:\exchange\OfflineDatensätze\bP Rapid\NOK\EthSpy Fehler\D0001Z001\offlineDataset.zip;

The error happens in zip_source_win32utf8.c (line 62):
/* Convert fname from UTF-8 to Windows-friendly UTF-16. */ size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, fname, -1, NULL, 0); if (size == 0) { zip_error_set(error, ZIP_ER_INVAL, 0); return NULL; }

Seems like the function MultiByteToWideChar returns zero, but I can´t imagine why.

@dillof
Copy link
Member

dillof commented Oct 11, 2018

Maybe the file name is not encoded in UTF-8, but some other encoding like ISO-8859-1. If so, you will have to convert it to UTF-8 before passing it to libzip.

@ZockerFloh7
Copy link
Author

Okay, I have not much experience with encodings, here is the part of the code, where I try to open the archive:

c_archive = zip_open(c_fileName.c_str(), ZIP_RDONLY, &error);

c_fileName is just a std::string, I get it from a file choosing dialog.
Can this be the problem?
Can you tell me how to convert it to utf8?

@dillof
Copy link
Member

dillof commented Oct 11, 2018

Sorry, I'm not a Windows developer. Examine c_fileName to see wether it is in UTF-8.

@ZockerFloh7
Copy link
Author

It seems like c_fileName is Latin(ISO-8859-1) encoded.
I converted it to UTF8 now, and its working with umlauts.
Thank you for your great support!

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

No branches or pull requests

2 participants