fix out of bounds index in card customizer (#3733)
What changed, and why it matters
This commit fixes a UI bug in Cake Wallet's card customizer. Previously, when picking a card color, the app could compute an index that pointed past the end of the available color list, which could cause a crash or display glitch. The fix uses the actual filtered color list when computing the selected index and falls back to the first color instead of an invalid position.
No immediate security action required; treat as a routine bug fix. Verify the color picker no longer crashes for wallets with special card designs or in Lightning mode.
Security signals we found
Out-of-bounds index / array access corrected
UI state initialization bug in wallet card customizer
Possible crash/DoS in non-security-critical feature
Evidence from the diff
The patch addresses an out-of-bounds index in CardCustomizerBloc. _initSelectedColor previously searched CardDesign.allGradients and, on miss, returned allGradients.length. That value could exceed the length of the effective availableColors list (which may be shorter because special-currency gradients are appended). The fix passes availableColors into _initSelectedColor, searches within that list, and returns 0 on miss. It also introduces a _currency getter that respects lightningMode, ensuring special designs are looked up with the correct currency key.
Changed components
lib/new-ui/viewmodels/card_customizer/card_customizer_bloc.dartInspect captured patch +8 / −6
### lib/new-ui/viewmodels/card_customizer/card_customizer_bloc.dart
@@ -46,10 +46,12 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
bool get _accountNameEnabled => !lightningMode &&
(_wallet.hasNativeAccounts || _wallet.walletInfo.isMultiAccountsEnabled == true);
+ CryptoCurrency get _currency => lightningMode ? CryptoCurrency.btcln : _wallet.currency;
+
List<Gradient> _updateAvailableColors(CardDesign currentDesign) {
final list = List<Gradient>.from(CardDesign.allGradients, growable: true);
- if (CardDesign.specialDesignsForCurrencies[_wallet.currency] != null) {
- list.add(CardDesign.specialDesignsForCurrencies[_wallet.currency]!.gradient);
+ if (CardDesign.specialDesignsForCurrencies[_currency] != null) {
+ list.add(CardDesign.specialDesignsForCurrencies[_currency]!.gradient);
}
return list;
}
@@ -111,9 +113,9 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
return settings.iconStyleIndex;
}
- int _initSelectedColor(CardDesign currentDesign) {
- final ret = CardDesign.allGradients.indexOf(currentDesign.gradient);
- return ret == -1 ? CardDesign.allGradients.length : ret;
+ int _initSelectedColor(CardDesign currentDesign, List<Gradient> availableColors) {
+ final ret = availableColors.indexOf(currentDesign.gradient);
+ return ret == -1 ? 0 : ret;
}
Future<void> _init(_Init event, Emitter<CardCustomizerState> emit) async {
@@ -126,7 +128,7 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
final availableDesigns = _initAvailableDesigns(lightningMode: lightningMode);
final availableColors = _updateAvailableColors(currentDesign);
final selectedDesignIndex = _initSelectedDesign(currentDesign);
- final selectedColor = _initSelectedColor(currentDesign);
+ final selectedColor = _initSelectedColor(currentDesign, availableColors);
final availableIconPaths = CardDesign.iconPathsForWalletType(curr);
final selectedIconIndex = _initSelectedIconIndex(currentDesignSettings, availableIconPaths);
Why this scored 22/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.