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. Closes #1019 add changelog entry
This commit is contained in:
parent
f5e7c027af
commit
c736dd37fb
|
@ -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.
|
||||
|
|
|
@ -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<UInt8>) {
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue