[release/5.0] Make sure we consider buffer length when marshalling back Unicode ByValTStr fields #54752
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Port #54695 to release/5.0
Customer Impact
The customer is trying to read a BSTR representing "012", into two strings "01" a "2" based on the buffer size. The strings point to the correct position but the parsing doesn't stop at buffer size, so the result is "012" and "2". The customer's scenario is a 64 character long string with 13 fields, this is the repro they reported the issue with.
Instead of reading only up to the constant buffer length based on the string marshalling data, the runtime would read until it found a null terminator. In the case described by the user, it would read the whole string instead of just the two characters. If the buffer itself is not null-terminated (since is supposed to be constant length), then it would read significantly more data than it was supposed to and create a string from that.
Testing
Testing added in PR.
Risk
Low. We have unit tests validating multiple edge cases with the scenario
Regression
This is a regression from 3.1