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
[SR-11091] String append Segmentation fault after reserveCapacity with argument smaller than required for existing String #53483
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
crash
Bug: A crash, i.e., an abnormal termination of software
standard library
Area: Standard library umbrella
String
Area → standard library: The `String` type
swift 5.9
Comments
cc @milseman |
AnthonyLatsis
added
the
crash
Bug: A crash, i.e., an abnormal termination of software
label
Dec 12, 2022
natecook1000
added a commit
to natecook1000/swift
that referenced
this issue
May 13, 2023
When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current capacity for native strings or the UTF-8 count for non-native strings as the minimum. At the same time, it removes a growth factor from that calculation, as the appropriate growth is already being factored in upstream at all call sites. rdar://109275875 Fixes apple#53483.
natecook1000
added a commit
to natecook1000/swift
that referenced
this issue
May 13, 2023
When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current UTF-8 count as the minimum. At the same time, it removes a growth factor from that calculation, as the appropriate growth is already being factored in upstream at all call sites. rdar://109275875 Fixes apple#53483
natecook1000
added a commit
that referenced
this issue
May 17, 2023
When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current UTF-8 count as the minimum. Non-native or non-unique strings now allocate the requested capacity (or space enough for the current contents, if that's larger than what's requested). rdar://109275875 Fixes #53483
natecook1000
added a commit
to natecook1000/swift
that referenced
this issue
May 17, 2023
When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current UTF-8 count as the minimum. Non-native or non-unique strings now allocate the requested capacity (or space enough for the current contents, if that's larger than what's requested). rdar://109275875 Fixes apple#53483
AnthonyLatsis
added
String
Area → standard library: The `String` type
swift 5.9
and removed
run-time crash
Bug → crash: Swift code crashed during execution
labels
May 17, 2023
natecook1000
added a commit
to natecook1000/swift
that referenced
this issue
May 17, 2023
When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current UTF-8 count as the minimum. Non-native or non-unique strings now allocate the requested capacity (or space enough for the current contents, if that's larger than what's requested). rdar://109275875 Fixes apple#53483
meg-gupta
pushed a commit
to meg-gupta/swift
that referenced
this issue
May 22, 2023
When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current UTF-8 count as the minimum. Non-native or non-unique strings now allocate the requested capacity (or space enough for the current contents, if that's larger than what's requested). rdar://109275875 Fixes apple#53483
NuriAmari
pushed a commit
to NuriAmari/swift
that referenced
this issue
May 28, 2023
When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current UTF-8 count as the minimum. Non-native or non-unique strings now allocate the requested capacity (or space enough for the current contents, if that's larger than what's requested). rdar://109275875 Fixes apple#53483
stephentyrone
pushed a commit
that referenced
this issue
Jun 1, 2023
When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current UTF-8 count as the minimum. Non-native or non-unique strings now allocate the requested capacity (or space enough for the current contents, if that's larger than what's requested). rdar://109275875 Fixes #53483
stephentyrone
pushed a commit
that referenced
this issue
Jul 25, 2023
* [stdlib] Fix String.reserveCapacity underallocation (#65902) When called on a string that is not uniquely referenced, `String.reserveCapacity(_:)` ignores the current capacity, using the passed-in capacity for the size of its new storage. This can result in an underallocation and write past the end of the new buffer. This fix changes the new size calculation to use the current UTF-8 count as the minimum. Non-native or non-unique strings now allocate the requested capacity (or space enough for the current contents, if that's larger than what's requested). rdar://109275875 Fixes #53483 * Fix String capacity growth tests for watchOS watchOS devices can have different allocation characteristics from other devices. This modifies the string capacity growth tests to be more flexible about measuring the growth in capacity, specifically when more is allocated than requested.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
crash
Bug: A crash, i.e., an abnormal termination of software
standard library
Area: Standard library umbrella
String
Area → standard library: The `String` type
swift 5.9
Attachment: Download
Environment
Xcode Version 11.0 beta 4 (11M374r)
Apple Swift version 5.1 (swiftlang-1100.0.257.2 clang-1100.0.31.3)
macOS 10.14.5 (18F132)
Additional Detail from JIRA
md5: 85de7713cc04dcda625434e59758a5c1
Issue Description:
How to reproduce, attached as StringReserveCapacityCrash.swift, not minimised:
The text was updated successfully, but these errors were encountered: