Skip to content

Conversation

ttys3
Copy link
Contributor

@ttys3 ttys3 commented Mar 24, 2024

the bug will cause CJK chars in filename been stripped out.

for example:

/media/mydisk/fooにほん.rar will result in /media/mydisk/foo  so the open will fail

due to

    std::string AnsiArcName;
    if (r->ArcName!=nullptr)
    {
      AnsiArcName=r->ArcName;
      if (!AreFileApisANSI())
        IntToExt(r->ArcName,AnsiArcName);
    }

    std::wstring ArcName;
    if (r->ArcNameW!=nullptr && *r->ArcNameW!=0)
      ArcName=r->ArcNameW;
    else
      CharToWide(AnsiArcName,ArcName);

    Data->Cmd.AddArcName(ArcName);
    Data->Cmd.Overwrite=OVERWRITE_ALL;
    Data->Cmd.VersionControl=1;

    Data->Cmd.Callback=r->Callback;
    Data->Cmd.UserData=r->UserData;

    // Open shared mode is added by request of dll users, who need to
    // browse and unpack archives while downloading.
    Data->Cmd.OpenShared = true;
    if (!Data->Arc.Open(ArcName,FMF_OPENSHARED))
    {
      r->OpenResult=ERAR_EOPEN;
      delete Data;
      return NULL;
    }

in Data->Arc.Open it will do WideToChar which cause the CJK bytes got lost.

but if it calls CharToWide first (when ArcNameW is nullptr), when it do the reverse, it get the right filename back.

@ttys3 ttys3 force-pushed the fix-cjk-file-open branch from 93b57dd to e63fc20 Compare March 24, 2024 03:17
the bug will cause CJK chars in filename been stripped out.

for example:

`/media/mydisk/fooにほん.rar`  will result in `/media/mydisk/foo` so the open will fail

due to

```cpp
    std::string AnsiArcName;
    if (r->ArcName!=nullptr)
    {
      AnsiArcName=r->ArcName;
      if (!AreFileApisANSI())
        IntToExt(r->ArcName,AnsiArcName);
    }

    std::wstring ArcName;
    if (r->ArcNameW!=nullptr && *r->ArcNameW!=0)
      ArcName=r->ArcNameW;
    else
      CharToWide(AnsiArcName,ArcName);

    Data->Cmd.AddArcName(ArcName);
    Data->Cmd.Overwrite=OVERWRITE_ALL;
    Data->Cmd.VersionControl=1;

    Data->Cmd.Callback=r->Callback;
    Data->Cmd.UserData=r->UserData;

    // Open shared mode is added by request of dll users, who need to
    // browse and unpack archives while downloading.
    Data->Cmd.OpenShared = true;
    if (!Data->Arc.Open(ArcName,FMF_OPENSHARED))
    {
      r->OpenResult=ERAR_EOPEN;
      delete Data;
      return NULL;
    }
```

in `Data->Arc.Open` it will do `WideToChar` which cause the CJK bytes got lost.

but if it calls `CharToWide` first (when `ArcNameW` is nullptr), when it do the reverse, it get the right filename back.
@muja
Copy link
Owner

muja commented Aug 29, 2024

I don't know why I cannot run checks on this PR... GitHub is really annoying... I opened #54 and some checks fail, can you check over there?

@ttys3
Copy link
Contributor Author

ttys3 commented Aug 31, 2024

I don't know why I cannot run checks on this PR... GitHub is really annoying... I opened #54 and some checks fail, can you check over there?

OK, I'll close this one

@ttys3 ttys3 closed this Aug 31, 2024
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

Successfully merging this pull request may close these issues.

2 participants