muja / unrar.rs

Rust library for extracting, listing and testing RAR archives.
Apache License 2.0
95 stars 22 forks source link

fix: fix CJK filename can not open issue #49

Closed ttys3 closed 2 months ago

ttys3 commented 7 months ago

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.

muja commented 2 months ago

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 commented 2 months ago

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