diff --git a/CHANGELOG.md b/CHANGELOG.md index bf6ccf73..6bc0aba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased +## Fixed +- The backend method proposeShielding checks the pointer for a null value before attempting to construct the Data with it. Without this check, proposeShielding would crash when there were either zero funds to shield or when the amount was less than the threshold defined by the client. + # 2.1.5 - 2024-04-18 ## Changed diff --git a/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift b/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift index 6377fd4d..7b6ff33e 100644 --- a/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift +++ b/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift @@ -752,11 +752,15 @@ struct ZcashRustBackend: ZcashRustBackendWelding { ) guard let proposal else { - throw ZcashError.rustShieldFunds(lastErrorMessage(fallback: "`proposeShielding` failed with unknown error")) + throw ZcashError.rustShieldFunds(lastErrorMessage(fallback: "Failed with nil proposal.")) } defer { zcashlc_free_boxed_slice(proposal) } - + + guard proposal.pointee.ptr != nil else { + throw ZcashError.rustShieldFunds(lastErrorMessage(fallback: "Insufficient funds to shield.")) + } + return try FfiProposal(contiguousBytes: Data( bytes: proposal.pointee.ptr, count: Int(proposal.pointee.len)