Skip to content

Conversation

@jmschonfeld
Copy link
Contributor

_NSCFString.getBytes does not currently read/respect the provided max buffer length when writing bytes out to the provided buffer. When an insufficiently sized buffer is provided, a buffer overflow occurs. This appeared as a symptom in plutil where reading a plist with a long unicode string would cause a buffer overflow since the UTF16 count was small enough for plutil to use a stack buffer instead of a dynamically-sized heap buffer, but the UTF8 count was long enough that writing the bytes overflows the stack buffer. This PR resolves the issue by breaking during byte iteration when we reach the max buffer length.

@jmschonfeld
Copy link
Contributor Author

@swift-ci test

@jmschonfeld
Copy link
Contributor Author

This caused a new test failure:

[2025-11-11T20:35:39.977Z] Test Suite 'TestMeasurement' started at 2025-11-11 20:35:39.877
[2025-11-11T20:35:39.977Z] Test Case 'TestMeasurement.testCodingRoundtrip' started at 2025-11-11 20:35:39.877
[2025-11-11T20:35:39.977Z] TestFoundation/Utilities.swift:247: error: TestMeasurement.testCodingRoundtrip : XCTAssertTrue failed - The fixture with identifier 'NSMeasurement-Angle' failed to match after an in-memory roundtrip.
[2025-11-11T20:35:39.977Z] Test Case 'TestMeasurement.testCodingRoundtrip' failed (0.003 seconds)

This failure doesn't occur on the base release/6.2 branch so it appears to be due to this change and needs further investigation. I suspect it's related to round tripping the symbol property of the angle measurement which likely uses a non-ASCII string

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.

Segmentation fault when Linux plutil tries to convert a single non-ascii string of sufficiently long size to binary plist.

1 participant