Skip to content

Commit 574ca17

Browse files
committed
MediaInfoRetriever:
* Fix potential encoding issue in `SetLanguage` method: explicitly convert the UTF-8 file content to UTF-16
1 parent a00c49d commit 574ca17

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ insert_final_newline = true
77
charset = utf-8
88
indent_style = space
99
indent_size = 2
10+
11+
[test.js]
12+
charset = utf-16

src/DOpusScriptingExtensions/MediaInfoRetriever/MediaInfoRetriever.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,23 @@ class ATL_NO_VTABLE CMediaInfoRetriever :
7979

8080
private:
8181
std::wstring GetLanguageFileContent(const std::wstring_view& languageName) {
82-
const auto& languageFilePath = boost::dll::this_line_location().parent_path() / L"MediaInfoLanguages" / std::format(L"{}.csv", languageName);
82+
const auto& languageFilePath = mediaInfoLanguagesPath / std::format(L"{}.csv", languageName);
8383

8484
if(!boost::filesystem::exists(languageFilePath)) {
8585
THROW_WEXCEPTION(L"Language '{}' is not supported. The '{}' file doesn't exist", languageName, languageFilePath);
8686
}
8787

88-
std::wifstream file(languageFilePath.c_str(), std::ios::binary);
88+
// The language files are encoded in UTF-8.
89+
std::ifstream file(languageFilePath.c_str());
8990
if (!file) {
9091
std::error_code ec(errno, std::generic_category());
9192
THROW_WEXCEPTION(L"Failed to open language file '{}'. Error message: {}", languageFilePath, ToWide(ec.message()));
9293
}
9394

94-
return (std::wostringstream() << file.rdbuf()).str();
95+
return ToWide(std::string{ std::istreambuf_iterator<char>(file), {} });
9596
}
9697

98+
inline static const auto& mediaInfoLanguagesPath = boost::dll::this_line_location().parent_path() / L"MediaInfoLanguages";
9799
MediaInfoLib::MediaInfo mi;
98100
};
99101

src/Test/test.js

25.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)