Skip to content

Prevent null character in Windows home directory #808

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

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Jul 31, 2024

Resolves #807

String(decoding:as:) was including the null-terminator from the Windows API, and when this is passed to URL, it's encoded in the form file:///C:/Users/alex%00/. When enumerating the directory, we get the file system representation of the URL, which decodes %00 to back to \0. This was causing us to append a file name alex to the directory, getting file:///C:/Users/alex%00/alex, which "exists" because it was only checking for the existence of file:///C:/Users/alex. This cycle repeats, causing an infinite loop in the enumerator.

This PR 1) replaces String(decoding:as:) with String(decodingCString:as:) in the home directory function and 2) prevents URL.fileSystemPath from decoding %00 to \0.

@jrflat
Copy link
Contributor Author

jrflat commented Jul 31, 2024

@swift-ci please test

@parkera parkera requested review from compnerd and jmschonfeld July 31, 2024 22:55
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Ah, the W terminator is \0\0. Nice catch!

Copy link
Contributor

@jmschonfeld jmschonfeld left a comment

Choose a reason for hiding this comment

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

Thanks!

@compnerd
Copy link
Member

compnerd commented Aug 1, 2024

@jrflat anything left to do here, or good to merge?

@jrflat
Copy link
Contributor Author

jrflat commented Aug 2, 2024

Will merge soon after some testing on Darwin

@jrflat jrflat merged commit 628fe67 into swiftlang:main Aug 2, 2024
3 checks passed
jrflat added a commit to jrflat/swift-foundation that referenced this pull request Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants