24 Commits

Author SHA1 Message Date
Jake Petroules
90953dfb68
Transparently add the \\?\ prefix to Win32 calls for extended length path handling (#1257)
On Windows, there is a built-in maximum path limitation of 260 characters under most conditions. This can be extended to 32767 characters under either of the following two conditions:

- Adding the longPathAware attribute to the executable's manifest AND enabling the LongPathsEnabled system-wide registry key or group policy.
- Ensuring fully qualified paths passed to Win32 APIs are prefixed with \?\

Unfortunately, the former is not realistic for the Swift ecosystem, since it requires developers to have awareness of this specific Windows limitation, AND set longPathAware in their apps' manifest AND expect end users of those apps to change their system configuration.

Instead, this patch transparently prefixes all eligible paths in calls to Win32 APIs with the \?\ prefix to allow them to work with paths longer than 260 characters without requiring the caller of Foundation to manually prefix the paths.

See https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation for more info.
2025-04-23 14:51:43 -07:00
Jeremy Schonfeld
93e3bac3d9
(144909030) FSR writes bytes to end of buffer even on success cases (#1199) 2025-03-04 21:54:29 -08:00
Jeremy Schonfeld
f337a2c04f
Prevent potential buffer over-reads of file system representations (#1124)
* (133687793) Prevent buffer over-reads with string file system representations that fail

Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>

* Account for empty buffers

Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>

* Move empty buffer check earlier

Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>

---------

Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>
2025-01-21 10:37:09 -08:00
Tony Parker
446af5c0c5
Formatting performance improvements (#884) 2024-08-23 14:13:17 -07:00
Tony Parker
90109a4cf6
Revert formatting performance improvements (#744)
There appears to be some kind of race or memory smash in ICU after these, and we need more time to investigate the full root cause.
2024-07-18 17:43:34 -07:00
Tony Parker
6ee772ba7f
Improve performance of FormatStyle formatting when used in multithreaded context (#719)
* Improve performance of FormatStyle formatting when used in multithreaded context

* Change canImport statement to support newer SDK on older macOS
2024-07-09 10:06:47 -07:00
Saleem Abdulrasool
654fa54be7
FoundationEssentials: canonicalise the arc separator more aggressively (#669)
When trying to get the file system representation of a string, we may
have previously used `appendingPathComponent(_:)` which will have used
the incorrect separator. Ensure that all the separators are properly
converted prior to returning the path.
2024-06-07 17:16:39 -07:00
Saleem Abdulrasool
50d7537507
FoundationEssentials: handle canonical and non-canonical paths (#668)
In the case that the path is canonicalised, the `/` would be replaced
with `\`. The leading `\` would interfere with our ability to recognise
the absolute path representation and thus get the wrong response.
2024-06-07 09:20:18 -07:00
Saleem Abdulrasool
f29e378d8f
FoundationEssentials: strip leading / (#627)
When creating a file system representation from the path, we need to
strip the leading `/` which is added for the RFC representation of the
Windows path. Without this, the C runtime will fail with an invalid
argument error. Unfortunately this regresses the test suite by causing a
hang.
2024-05-29 13:29:15 -07:00
Saleem Abdulrasool
8bdf040aef
(128006071) FoundationEssentials: simplify path normalization (#603)
We would previously conditionally call `GetFullPathNameW` and do string
manipulations for normalising the path. Instead, always call
`GetFullPathNameW` to normalise the path as per Windows' rules. This
more importantly will collapse runs of the arc separator, which is
crucial when using extended paths as the NT path form must always use
the normalised paths or the access will fail.
2024-05-13 13:05:31 -07:00
Saleem Abdulrasool
1dea76a35f
FoundationEssentials: correct an off-by-one error on Windows (#587)
The returned value in the success case does not account for the
terminating nul character, resulting in the value being 1 less than the
allocation required. This was causing a spurious failure and thus unable
to compute the location of the process.
2024-05-06 09:29:24 -07:00
Jeremy Schonfeld
a5f9a9431d
(122557036) Add autoreleasepool to __swiftFillFileSystemRepresentation (#574) 2024-05-01 14:13:17 -07:00
Saleem Abdulrasool
3a7c84e3f6
FoundationEssentials: add withNTPathRepresentation (#531)
This helper allows us to convert paths to the NT path representation.
The NT Path representation is important for internal usage as it allows
us to bypass the `MAX_PATH` (261) limit for Win32 APIs. In order to do
this, we simply escape the string with the NT prefix (`\\?\`) which
requires that the path is normalised (uses `\` rather than `/`) and
generally should be an absolute path. Using the NT path allows us to use
the fully supported 32k character path length of the NT kernel.

Co-authored-by: Alexander Smarus <bender@readdle.com>
Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>
2024-04-09 14:22:32 -07:00
Jeremy Schonfeld
61f97b6e52
(123444217) Avoid filling FSR with partial scalars on failure 2024-04-09 09:29:54 -07:00
Jeremy Schonfeld
e5211f2926
(122981400) Standardize on using internal import 2024-03-06 13:42:02 -08:00
Jeremy Schonfeld
039c4d683c
Efficient buffer size calculation for String file system representation
* Use smaller buffer for file system representation

* Reword scalars -> code-units

Co-authored-by: Karl <5254025+karwa@users.noreply.github.com>

---------

Co-authored-by: Karl <5254025+karwa@users.noreply.github.com>
2024-02-13 13:21:16 -08:00
Jeremy Schonfeld
39dc85e87c
(122536991) File system representations should not be limited to PATH_MAX 2024-02-09 16:33:38 -08:00
Jeremy Schonfeld
a163cbe9a8
(122199292) Guard against UTF8 buffers from large strings 2024-02-02 16:37:59 -08:00
Tony Parker
4499edd7b1
Implement Data reading and writing (#377)
* Implement Data reading and writing

* Use swift-foundation-local for dependency name in benchmark
2024-01-17 13:04:41 -08:00
Jeremy Schonfeld
7f1bcff03b
Fix an off by one error in Strings file system representation 2024-01-04 13:42:50 -08:00
Jeremy Schonfeld
ea334c656b
(118839391) Implement file system representation for String
* (118839391) Implement file system representation for String

* (118839391) Fix some build issues

* (118839391) Fix embedded nulls and precomposed characters
2023-12-14 10:02:20 -08:00
Tony Parker
3d52b255b7
Move String additions from _FoundationInternals to FoundationEssentials + package (#282) 2023-10-04 16:38:28 -07:00
Tony Parker
9fae9b1c6b
Revert "Move String additions from _FoundationInternals to FoundationEssentials + package" (#281)
This reverts commit 3a17834c7f397c9b83085008cad99eca7d7f3735.
2023-10-04 15:39:55 -07:00
Tony Parker
3a17834c7f
Move String additions from _FoundationInternals to FoundationEssentials + package 2023-10-04 15:24:17 -07:00