Skip to content

Replication: Detect RTTI on GCC/Clang in CheckedEntityCast - #285

Closed
Kheartz wants to merge 1 commit into
MafiaHub:developfrom
Kheartz:rtti_detect_gcc_clang
Closed

Kheartz wants to merge 1 commit into
MafiaHub:developfrom
Kheartz:rtti_detect_gcc_clang

Conversation

@Kheartz

@Kheartz Kheartz commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

CheckedEntityCast<T> (added in 75263da) uses dynamic_cast only under #if defined(_CPPRTTI). MSVC is the only compiler that defines _CPPRTTI. GCC and Clang signal RTTI with __GXX_RTTI, so on Linux every build falls through to the /GR- fallback, even with RTTI on. That fallback needs T::kTypeName, and any typed wrapper instantiated on a type without one fails to compile. ReplicationManager::GetEntity<T>, GetViewerAs<T>, ForEach<T> and EntityCollection all go through this cast.

HogwartsMP's Linux server hits this: its entity types register by name constants and don't declare kTypeName.

Failed HogwartsMP build: https://github.com/hogwarts-mp/mod/actions/runs/36290998653/job/108540951455

replication_manager.h:46:93: error: 'kTypeName' is not a member of 'HogwartsMP::Shared::HumanEntity'

Windows builds were unaffected. The framework's own CI only instantiates the cast on TextLabelEntity, which does declare kTypeName, so it didn't catch this.

Change

#if defined(_CPPRTTI) || defined(__GXX_RTTI)

MSVC behaviour doesn't change. GCC and Clang with RTTI on now use dynamic_cast like MSVC does. Builds with /GR- or -fno-rtti still use the type-id check.

Testing

Not compiled locally on Linux (no GCC toolchain here). GCC and Clang define __GXX_RTTI whenever RTTI is on and leave it undefined under -fno-rtti.

CheckedEntityCast picked dynamic_cast only under _CPPRTTI, which only
MSVC defines. GCC and Clang builds with RTTI on fell through to the
kTypeName id check, so a downstream Linux server stopped compiling on
entity types that do not declare kTypeName. Also accept __GXX_RTTI.
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: be77dcdc-5bcd-44c9-81f9-0d4b93c518d5

📥 Commits

Reviewing files that changed from the base of the PR and between c8a58ff and 9e35721.

📒 Files selected for processing (1)
  • code/framework/src/networking/replication/replication_manager.h

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

CheckedEntityCast now detects RTTI support with _CPPRTTI or __GXX_RTTI. Builds without RTTI continue to use the registered-type-ID fallback.

Changes

Entity casting

Layer / File(s) Summary
RTTI detection and fallback
code/framework/src/networking/replication/replication_manager.h
CheckedEntityCast uses dynamic_cast when _CPPRTTI or __GXX_RTTI indicates RTTI is enabled. Comments describe compiler coverage and the fallback’s T::kTypeName requirement.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: segfaultd

Merge Risk: ⚪ Minimal · up to 9e357

RTTI-enabled GCC/Clang builds use polymorphic entity casts, while RTTI-disabled builds retain the registered-type-ID fallback. The inspected callers are compatible, and no actionable merge risk is established.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 9e357

On GCC and Clang builds with RTTI enabled, typed entity lookups can now accept subclasses where the previous fallback required an exact registered type. No authorization bypass is demonstrated, but the effect on external consumers is unknown.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed type matching is reachable through typed replication APIs in GCC/Clang RTTI builds. The supplied evidence does not establish which external callers, if any, expose those APIs to attacker-controlled identifiers.

Trust Boundaries and Controls

  • observed — The fallback compares a registered type ID, while the RTTI branch checks C++ type compatibility. The wrappers apply either check after obtaining an entity pointer; they do not themselves establish caller authority.

Hardening Proposals

  • proposed — Document the exact-type versus subtype-matching distinction so consumers that require an exact registered type can check it explicitly.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding GCC/Clang RTTI detection to CheckedEntityCast.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each cast with care
RTTI paths now reach the lair
When RTTI sleeps, the IDs stay
The fallback still knows the way
Soft paws mark this tidy change today

Comment @coderabbitai help to get the list of available commands.

@Kheartz

Kheartz commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed with alternative approach downstream.

@Kheartz Kheartz closed this Sep 27, 2026
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.

1 participant