Best-Fit
#Windows
UnicodeからANSIに変換する
一致する文字が無い場合にそれっぽいのに変換するのがBest-Fit
https://learn.microsoft.com/ja-jp/dotnet/standard/base-types/character-encoding#BestFit
コードページごとの対応付け https://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/
https://worst.fit/mapping/
WorstFit
Best-Fitの思わぬ変換が脆弱性になる
https://blog.orange.tw/posts/2025-01-worstfit-unveiling-hidden-transformers-in-windows-ansi/
CVE-2024-4577
Soft Hyphen U+00ADがハイフンに変換されて引数として解釈される
円記号がバックスラッシュに変換されてパストラバーサル
引数の分割
呼ぶ側がダブルクォーテーションをエスケープしていても
"foo¥\" bar"
呼ばれた側がGetCommandLineAを使った場合
"foo\\" bar"と解釈される
円記号U+00A5がバックスラッシュに変換されてダブルクォーテーションがエスケープされなくなる
int main()はGetCommandLineAを呼ぶ
int wmain()を使うべき
https://learn.microsoft.com/ja-jp/cpp/c-language/using-wmain?view=msvc-170