Skip to content

Fix 32-bit truncation in the flagset u64 round-trip - #7757

Merged
Goober5000 merged 1 commit into
scp-fs2open:masterfrom
Goober5000:fix/flagset_64bit
Aug 31, 2026
Merged

Fix 32-bit truncation in the flagset u64 round-trip#7757
Goober5000 merged 1 commit into
scp-fs2open:masterfrom
Goober5000:fix/flagset_64bit

Conversation

@Goober5000

Copy link
Copy Markdown
Contributor

Mission flags are saved to the mission file as the full 64-bit flagset value, but three issues prevented anything larger than 32 bits from being saved as intended:

  • stuff_flagset parsed the value with stuff_long, where atol clamps anything above LONG_MAX
  • flagset::from_u64 cast the incoming value to unsigned long, truncating bits 32-63
  • flagset::to_u64 used bitset::to_ulong where it should use bitset::to_ullong

Fix these issues and add static_assert in the flagset functions to defend against future issues. Also use the proper UINT64_T_ARG where it should be used.

This was first triggered by Limited_support_rearm_pool, the first mission flag to occupy bit 31. Only mission flags are affected; the other flagset serialization paths were audited and are safe.

Mission flags are saved to the mission file as the full 64-bit flagset value, but three issues prevented anything larger than 32 bits from being saved as intended:

 * `stuff_flagset` parsed the value with `stuff_long`, where `atol` clamps anything above `LONG_MAX`
 * `flagset::from_u64` cast the incoming value to `unsigned long`, truncating bits 32-63
 * `flagset::to_u64` used `bitset::to_ulong` where it should use `bitset::to_ullong`

Fix these issues and add `static_assert` in the flagset functions to defend against future issues.  Also use the proper UINT64_T_ARG where it should be used.

This was first triggered by `Limited_support_rearm_pool`, the first mission flag to occupy bit 31.  Only mission flags are affected; the other flagset serialization paths were audited and are safe.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Goober5000 Goober5000 added the fix A fix for bugs, not-a-bugs, and/or regressions. label Aug 30, 2026
@wookieejedi wookieejedi added the Point Release Candidate An already merged bugfix that may be merged into a previous stable version label Aug 30, 2026
@wookieejedi wookieejedi added this to the Release 26.0.1 milestone Aug 30, 2026
@Goober5000
Goober5000 merged commit b08ab18 into scp-fs2open:master Aug 31, 2026
18 checks passed
@Goober5000
Goober5000 deleted the fix/flagset_64bit branch August 31, 2026 03:37
wookieejedi pushed a commit that referenced this pull request Sep 2, 2026
Fix 32-bit truncation in the flagset u64 round-trip
@wookieejedi wookieejedi added added to point release and removed Point Release Candidate An already merged bugfix that may be merged into a previous stable version labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

added to point release fix A fix for bugs, not-a-bugs, and/or regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants