Skip to content
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

[release/0.8] Backport 'Bugfix for UnicodeString constructor' #1306

Merged
merged 2 commits into from
Feb 24, 2022

Conversation

dcantah
Copy link
Contributor

@dcantah dcantah commented Feb 24, 2022

This cherry-picks two changes that fixed bugs when unpacking images that contained non-ascii characters.

0afb0c9
587be85


The existing UnicodeString constructor creates a unicode string object by taking the
length of a given GO string. This works fine for ASCII strings but fails when the input
string contains non ASCII characters. This change fixes it.

Description:

In the earlier version of NewUnicodeString the length would be set to the number of bytes in the string than the number of runes in the string. If the input string of 3 runes had one non-ascii character (i.e a character that would take 2 bytes to encode in UTF=8) the value of length would be 4 and the UnicodeString.Length & UnicodeString.MaximumLength would be set to 8. However, the buffer returned by UTF16FromString would include only 3 uint16s which is 6 valid bytes. So the generated UnicodeString would end up with garbage bytes at the end. Moreover the win32 UNICODE_STRING expects that the Length field should not include the terminating null character.

The above change fixes both of these issues by using the length returned by UTF16FromString .

The test was failing because the image that the test imports has an image that has a file with non-ASCII character in the name. So during the image extraction the safefile.OpenRelative call tries to convert that path to the UnicodeString to pass it to NtCreateFile and NtCreateFile fails with "The filename, directory name, or volume label syntax is incorrect".

The existing UnicodeString constructor creates a unicode string object by taking the
length of a given GO string. This works fine for ASCII strings but fails when the input
string contains non ASCII characters. This change fixes it.

Signed-off-by: Amit Barve <[email protected]>
(cherry picked from commit 0afb0c9)
Signed-off-by: Daniel Canter <[email protected]>
Signed-off-by: Amit Barve <[email protected]>
(cherry picked from commit 587be85)
Signed-off-by: Daniel Canter <[email protected]>
@dcantah dcantah requested a review from a team as a code owner February 24, 2022 21:19
@jterry75
Copy link
Contributor

THANK YOU!

Copy link
Contributor

@katiewasnothere katiewasnothere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dcantah dcantah merged commit f43a5f8 into microsoft:release/0.8 Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants