check_win only counts 13 cards per foundation — corrupt save permanently locks game #22

Closed
opened 2026-05-19 18:44:34 +00:00 by funman300 · 0 comments
Owner

File

solitaire_core/src/game_state.rs lines 420–426

Description

check_win returns true when each foundation pile has exactly 13 cards, without verifying card order or suit uniqueness. Under normal play this is safe because can_place_on_foundation enforces correctness. However, if a deserialized GameState from a corrupt or edited save file has 13 cards per foundation but they are not a valid A→K sequence, is_won becomes true and the GameAlreadyWon guard permanently blocks all further actions (draw, move_cards, undo) with no recovery path except deleting the save.

Fix

In check_win, additionally verify that each foundation pile's cards form a valid A–K sequence of a single suit, or add a validate() method on GameState that is called after deserialization.

## File `solitaire_core/src/game_state.rs` lines 420–426 ## Description `check_win` returns `true` when each foundation pile has exactly 13 cards, without verifying card order or suit uniqueness. Under normal play this is safe because `can_place_on_foundation` enforces correctness. However, if a deserialized `GameState` from a corrupt or edited save file has 13 cards per foundation but they are not a valid A→K sequence, `is_won` becomes `true` and the `GameAlreadyWon` guard permanently blocks all further actions (`draw`, `move_cards`, `undo`) with no recovery path except deleting the save. ## Fix In `check_win`, additionally verify that each foundation pile's cards form a valid A–K sequence of a single suit, or add a `validate()` method on `GameState` that is called after deserialization.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: funman300/Ferrous-Solitaire#22