-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix #3171 : 去掉生成绝对路径函数中的窄字符WindowsAPI调用,改用宽字符API和C++17 std::filesystem来避免win平台中文路径问题 #3255
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
Changes from all commits
391b62a
750f6a3
3e6f259
25c5a4e
f27c320
43db5d0
01881d3
989488c
853d5fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,16 +13,27 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef _WIN32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <windows.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <sys/stat.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <unistd.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <limits.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <stdlib.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "sherpa-onnx/csrc/macros.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace sherpa_onnx { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::wstring ToWideString(const std::string &s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string ToString(const std::wstring &s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
23
to
+26
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace sherpa_onnx { | |
| std::wstring ToWideString(const std::string &s); | |
| std::string ToString(const std::wstring &s); | |
| #include "sherpa-onnx/csrc/text-utils.h" | |
| namespace sherpa_onnx { |
Copilot
AI
Mar 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows ReadFile casts buffer.size() to DWORD for the ReadFile() call. For files >4GiB this overflows / truncates the requested read size; the function will then fail even though SIZE_MAX is larger. Consider rejecting sizes > DWORD max explicitly or reading in a loop/chunks.
| DWORD bytes_read = 0; | |
| if (!::ReadFile(hFile, buffer.data(), static_cast<DWORD>(buffer.size()), &bytes_read, nullptr) || | |
| bytes_read != buffer.size()) { | |
| return {}; | |
| } | |
| size_t total_read = 0; | |
| while (total_read < buffer.size()) { | |
| size_t remaining = buffer.size() - total_read; | |
| DWORD to_read = remaining > static_cast<size_t>(MAXDWORD) | |
| ? MAXDWORD | |
| : static_cast<DWORD>(remaining); | |
| DWORD bytes_read = 0; | |
| if (!::ReadFile(hFile, buffer.data() + total_read, to_read, &bytes_read, nullptr)) { | |
| return {}; | |
| } | |
| if (bytes_read == 0) { | |
| // Unexpected end of file | |
| return {}; | |
| } | |
| total_read += bytes_read; | |
| } |
Copilot
AI
Mar 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the non-Windows ReadFile path, tellg() can return -1 on failure; constructing std::vector<char> buffer(size) would then attempt a huge allocation due to signed-to-unsigned conversion. Check that size >= 0 (and that the stream is in a good state) before allocating.
Uh oh!
There was an error while loading. Please reload this page.