-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Fix input buffering for A APIs #16313
Fix input buffering for A APIs #16313
Conversation
for (const auto& s : til::utf16_iterator{ source }) | ||
{ | ||
char buffer[8]; | ||
const auto length = WideCharToMultiByte(cp, 0, &wch, 1, &buffer[0], sizeof(buffer), nullptr, nullptr); | ||
const auto length = WideCharToMultiByte(cp, 0, s.data(), gsl::narrow_cast<int>(s.size()), &buffer[0], sizeof(buffer), nullptr, nullptr); |
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.
I'm more confident now, Dustin (#14745 (comment)). 😄
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.
👀
6ba2b45
to
0e9a776
Compare
Would you be willing to pull the audit fixes into a separate PR? |
Sure! #16325 |
// * don't store anything in `_cachedTextA` | ||
// * leave "bc" in the `source` string, for the caller to handle | ||
// Otherwise we'll copy "a", store "b" and return "c", which is wrong. See GH#16223. | ||
if (target.empty()) |
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 this case, target.empty()
means target
is full, right? based on how bytes_transfer
works, the length will be zero when there is no space remaining
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.
Yes, exactly. The exit condition is still !source.empty()
as it was before but we now need to add target.empty()
as one, as described in the comment. This results in target.empty() || !source.empty()
, but the latter is already an implication of the former so we can shorten it.
This fixes an issue where character-wise reading of an input like "abc" would return "a" to the caller, store "b" as a partial translation (= wrong) and return "c" for the caller to store it for the next call. Closes #16223 Closes #16299 ## Validation Steps Performed * `ReadFile` with a buffer size of 1 returns inputs character by character without dropping any inputs ✅ --------- Co-authored-by: Dustin L. Howett <duhowett@microsoft.com> (cherry picked from commit 63b3820) Service-Card-Id: 91122022 Service-Version: 1.19
This fixes an issue where character-wise reading of an input like "abc" would return "a" to the caller, store "b" as a partial translation (= wrong) and return "c" for the caller to store it for the next call. Closes #16223 Closes #16299 ## Validation Steps Performed * `ReadFile` with a buffer size of 1 returns inputs character by character without dropping any inputs ✅ --------- Co-authored-by: Dustin L. Howett <duhowett@microsoft.com> (cherry picked from commit 63b3820) Service-Card-Id: 91108808 Service-Version: 1.18
This fixes an issue where character-wise reading of an input like "abc"
would return "a" to the caller, store "b" as a partial translation
(= wrong) and return "c" for the caller to store it for the next call.
Closes #16223
Closes #16299
Validation Steps Performed
ReadFile
with a buffer size of 1 returns inputs character bycharacter without dropping any inputs ✅