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

Special Characters in File Paths #93

Open
ajacquinot opened this issue Sep 4, 2024 · 1 comment
Open

Special Characters in File Paths #93

ajacquinot opened this issue Sep 4, 2024 · 1 comment

Comments

@ajacquinot
Copy link

ajacquinot commented Sep 4, 2024

Hello,
I'm currently using the gpujpeg_image_load_from_file function to open images in a C++ project. However, I've encountered an issue when trying to open files that have special characters in their names, such as (((φ(◎ロ◎;)φ))).jpg.
It seems that the function uses char* for the file path parameter and relies on fopen internally, which does not handle file paths with special characters as I wish.

Is there another way to open this file, or would it be possible to update the gpujpeg_image_load_from_file function to handle file paths with special characters? (Maybe by using wide-character strings (wchar_t*) and _wfopen on Windows)

Regards,
Adrien

@MartinPulec MartinPulec self-assigned this Sep 6, 2024
MartinPulec added a commit that referenced this issue Sep 6, 2024
@MartinPulec
Copy link
Collaborator

Hi,

thanks for reporting. I've tried with _wfopen, file name argument converted with MultiByteToWideChar with various codepages, CP_UTF8, CP_ACP - nothing worked.

Anyways, it seems like the value in argv is already incorrect, I've tried with 'φ' ("\xcf\x86" in UTF-8) and the particular argv[x] is single byte 0x66 ('f' in ASCII). I've tried also couple of other things like passing the value of phi to the function typed directly in code to C-str with MultiByteToWideChar(CP_UTF8,... conversion and _wfopen or without it (assuming multi-byte encoding to be understood by fopen). But without a success.

Is there another way to open this file,

You can of course open the file by yourself and read the data to a byte array - gpujpeg_decoder_decode() needs just the pointer to the buffer and its length. No need to use gpujpeg_image_load_from_file.

or would it be possible to update the gpujpeg_image_load_from_file function to handle file paths with special characters

I'd like to if i knew how to. I spent some time trying but without much success. So I cannot tell if I try any further.

Anyways, if you have some expertise or idea - could you make a minimal working example (POC) showing how to open such a file? Something like:

#include <cstdio>
int main(int argc, char *argv[]) {
    wchar_t *filename;
    // code to convert argv[1] to filename
    FILE *f = _wfopen(filename, L"rb");
    if (f) {
        puts("success!");
    }
}

(The string doesn't necessarily be passe from the command-line - if you write it to the code directly, I believe it will be OK as well, passing to gpujpeg_image_load_from_file is enough for you. This could be to work-around if there is some other problem passing the string from terminal.)

I am not sure if I don't have some problem with locales. So as a starting point to check if we both have the same situation, can you try?

#include <cstdio>
#include <cstring>
int main(int argc, char *argv[]) {
    printf("%zu\n", strlen(argv[1]));
}

and call it with φ as the argument? For me, it writes 1, which should not be the case unless you have Greek 8-bit encoding (I don't believe much of non-Greek 8b encodings have mapped the Greek alphabet)

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

No branches or pull requests

2 participants