From 363c2f7506608409f0787d1e34bc99dc7aef306d Mon Sep 17 00:00:00 2001 From: Masamune <125840508+Masamuneee@users.noreply.github.com> Date: Tue, 25 Aug 2026 10:54:40 +0700 Subject: [PATCH] wallet2: fix infinite loop in estimate_tx_size_and_weight on large n_outputs estimate_rct_tx_size() and estimate_tx_weight() compute the Bulletproof padded output count with `while ((1< 2^30 this reaches `1 << 31` (signed overflow, UB), and once the shift count exceeds the int width the value cycles and never reaches n_outputs, so the loop never terminates. estimate_tx_size_and_weight() accepts n_outputs up to INT_MAX (only negative is rejected), so a single wallet-rpc call spins the handling thread forever. Shift an unsigned 64-bit one and compare in uint64_t at all three shift sites, and accumulate the estimated size in size_t (cast the per-input and per-output terms) so the size arithmetic cannot overflow for large counts. (cherry picked from commit a3deaab98aeea87ed4b9e11d74a853d2b7ef9c37) (cherry picked from commit ac37e75df8aedf43aa7afa1199ec24e229039f34) --- src/wallet/wallet2.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 8e7144092..788ba3ba2 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -804,10 +804,10 @@ size_t estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra size += 1 + 6; // vin - size += n_inputs * (1+6+(mixin+1)*2+32); + size += (size_t)n_inputs * (1+6+((size_t)mixin+1)*2+32); // vout - size += n_outputs * (6+32); + size += (size_t)n_outputs * (6+32); // extra size += extra_size; @@ -821,31 +821,31 @@ size_t estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra if (bulletproof || bulletproof_plus || bulletproof_plus_full_commit) { size_t log_padded_outputs = 0; - while ((1<