From a3deaab98aeea87ed4b9e11d74a853d2b7ef9c37 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. --- 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 d4b375464..d6a830e48 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -806,10 +806,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; @@ -823,31 +823,31 @@ size_t estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra if (bulletproof || bulletproof_plus) { size_t log_padded_outputs = 0; - while ((1<