Skip to content

Fix crash when boolean fields in sunshine_state.json are stored as strings#1286

Merged
ClassicOldSong merged 1 commit intoClassicOldSong:masterfrom
LTe:config-parse-boolean-to-string
Dec 17, 2025
Merged

Fix crash when boolean fields in sunshine_state.json are stored as strings#1286
ClassicOldSong merged 1 commit intoClassicOldSong:masterfrom
LTe:config-parse-boolean-to-string

Conversation

@LTe
Copy link
Copy Markdown
Contributor

@LTe LTe commented Dec 16, 2025

Replace Boost property_tree with nlohmann::json in save_user_creds().

Boost property_tree does not preserve JSON types - it converts all values
to strings when writing JSON. This caused boolean and integer fields in
sunshine_state.json to become strings (e.g., true -> "true", 119480064 ->
"119480064") after changing the password, leading to crashes on restart.

nlohmann::json preserves the original types, matching the rest of the
codebase which already uses it for JSON operations.

@ClassicOldSong
Copy link
Copy Markdown
Owner

Weird, I have already changed the whole settings parsing to proper JSON handling and changing these fields never got me into problems. Were you upgraded from a very old version or have reverted to an old version?

You should have noticed the format migration code and these kind of things should be handled there instead.

@LTe
Copy link
Copy Markdown
Contributor Author

LTe commented Dec 16, 2025

@ClassicOldSong I can easily reproduce this on the fresh installation of version 0.4.6.

  1. Fresh install
  2. Set initial password
  3. Pair first device
  4. Change Language
  5. Save and Apply
  6. Login again
  7. Change password
  8. Login again
  9. Change language
  10. Save and apply
  11. Apollo is not starting

After this operation content of C:\Program Files\Apollo\config\sunshine_state.json

{
    "password": "[REDACTED]",
    "root": {
        "named_devices": [
            {
                "allow_client_commands": "true",
                "always_use_virtual_display": "false",
                "cert": "[REDACTED]",
                "display_mode": "",
                "enable_legacy_ordering": "true",
                "name": "Mac",
                "perm": "119480064",
                "uuid": "9D2B43B6-AACC-510E-C417-029F89C51463"
            }
        ],
        "uniqueid": "C9E57A7A-04A9-ED0B-F71E-BAF1C6E09943"
    },
    "salt": "HM5xwNFijUhDEp2o",
    "username": "apollo"
}

@LTe
Copy link
Copy Markdown
Contributor Author

LTe commented Dec 16, 2025

On the other hand I think boost::property_tree library does not output typed values in JSON and we always end up with string. So even when other parts of the code created boolean values it will just drop all the types and replace with string during password change.

So

pt::write_json(file, outputTree);
will cause issues.

Replace Boost property_tree with nlohmann::json in save_user_creds().

Boost property_tree does not preserve JSON types - it converts all values
to strings when writing JSON. This caused boolean and integer fields in
sunshine_state.json to become strings (e.g., true -> "true", 119480064 ->
"119480064") after changing the password, leading to crashes on restart.

nlohmann::json preserves the original types, matching the rest of the
codebase which already uses it for JSON operations.

Fixes ClassicOldSong#835
@LTe LTe force-pushed the config-parse-boolean-to-string branch from eb521c8 to 7ec7566 Compare December 16, 2025 21:28
@ClassicOldSong
Copy link
Copy Markdown
Owner

I think I have replaced all the occurrences of boost property tree...

Anyway thanks for finding this out!

@ClassicOldSong ClassicOldSong merged commit a40b179 into ClassicOldSong:master Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants