diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a55594b..7309191f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Unreleased +### [#1019] Memo has trailing garbled text + +Changes the way unpadded bytes are turned into a UTF-8 Swift String +without using cString assuming APIs that would overflow memory and +add garbled trailing bytes. + ### Changed - `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. diff --git a/Sources/ZcashLightClientKit/Model/Memo.swift b/Sources/ZcashLightClientKit/Model/Memo.swift index daa8a818..2b15c6f5 100644 --- a/Sources/ZcashLightClientKit/Model/Memo.swift +++ b/Sources/ZcashLightClientKit/Model/Memo.swift @@ -165,8 +165,8 @@ public extension MemoBytes { func intoMemo() throws -> Memo { switch self.bytes[0] { case 0x00 ... 0xF4: - let unpadded = self.unpaddedRawBytes() - guard let validatedUTF8String = String(validatingUTF8: unpadded) else { + let unpaddedBytes = self.unpaddedRawBytes() + guard let validatedUTF8String = String(bytes: unpaddedBytes, encoding: .utf8) else { throw ZcashError.memoBytesInvalidUTF8 } @@ -218,19 +218,6 @@ extension Array where Element == UInt8 { } } -extension String { - public init?(validatingUTF8 cString: UnsafePointer) { - guard let (str, _) = String.decodeCString( - cString, - as: UTF8.self, - repairingInvalidCodeUnits: false - ) else { - return nil - } - self = str - } -} - extension Optional where WrappedType == String { func intoMemo() throws -> Memo { switch self {