Skip to content

fix(llf,isl): guard degenerate inputs helpers#65

Merged
alandtse merged 1 commit into
devfrom
fix/llf-isl-degenerate-guards
May 30, 2026
Merged

fix(llf,isl): guard degenerate inputs helpers#65
alandtse merged 1 commit into
devfrom
fix/llf-isl-degenerate-guards

Conversation

@alandtse
Copy link
Copy Markdown
Owner

Summary

Three pre-existing robustness gaps in InverseSquareLighting and ShadowCasterManager, fixed in their current inline locations. These guard degenerate / corrupt inputs that can reach the GPU lighting path or dereference garbage.

Landing this before the Tier-2 test-extraction refactor (#56) keeps that PR behavior-preserving — #56 then extracts this already-fixed code into testable headers and adds the unit tests for these exact cases.

Fixes

  • InverseSquareLighting::CalculateRadius clamped only NaN. An exact-zero sqrt argument yields radius 0 (callers divide by radius, so a 0/0 attenuation fade), and a zero cutoffOverride yields +inf (sqrt(+inf) is not NaN, so the isnan-only check let it through). Now clamps any non-finite or non-positive result to 1.0.
  • ShadowCasterManager::ForEachShadowLight rejected null / non-canonical / misaligned pointers but not the low 64 KiB. A near-null garbage slot (e.g. 0x8) passed the check and was dereferenced (AV/CTD). Now also rejects raw < 0x10000 (the Windows x64 null-guard region is never a valid user mapping).
  • ComputeFrameTimePercentile90 guarded only count == 0; a negative count would drive a negative n into std::copy / std::nth_element (UB). Now guards <= 0.

Test plan

  • Full Release (ALL, SE/AE/VR universal) build succeeds; clean link, zero /W4 /WX warnings
  • Existing cpp suite passes (176 assertions / 47 cases) — no regression
  • Unit coverage for these degenerate paths lands with refactor(slf): extract Tier-2 testable helpers #56 once the helpers are extracted into testable headers

🤖 Generated with Claude Code

Pre-existing robustness gaps in code that Tier-2 test extraction is
about to move; fixing here first keeps that refactor behavior-preserving.

- InverseSquareLighting::CalculateRadius clamped only NaN. An exact-zero
  sqrt argument yields radius 0 (callers divide by radius -> 0/0 fade)
  and a zero cutoffOverride yields +inf (sqrt(+inf) is not NaN, so isnan
  missed it). Clamp any non-finite or non-positive result to 1.0.
- ForEachShadowLight rejected null / non-canonical / misaligned pointers
  but not the low 64 KiB. A near-null garbage slot (e.g. 0x8) passed and
  was dereferenced (AV/CTD). Reject raw below 0x10000.
- ComputeFrameTimePercentile90 guarded only count == 0; a negative count
  would drive a negative n into std::copy / std::nth_element (UB). <= 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 30, 2026 20:22
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Warning

Review limit reached

@alandtse, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f97ac6b0-44ea-4172-8c6f-d48bba833e63

📥 Commits

Reviewing files that changed from the base of the PR and between 38c247f and 1170b23.

📒 Files selected for processing (3)
  • src/Features/InverseSquareLighting.cpp
  • src/Features/LightLimitFix/ShadowCasterManager.cpp
  • src/Features/LightLimitFix/ShadowCasterManager.h
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/llf-isl-degenerate-guards

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

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens LightLimitFix and InverseSquareLighting helper paths against degenerate runtime inputs that could otherwise produce invalid GPU lighting data or unsafe shadow-light traversal.

Changes:

  • Rejects near-null shadow light pointers before dereferencing.
  • Handles negative frame-time sample counts with the existing fallback path.
  • Clamps non-finite or non-positive inverse-square radius results to 1.0f.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Features/LightLimitFix/ShadowCasterManager.h Adds a low-address guard to shadow light pointer plausibility checks.
src/Features/LightLimitFix/ShadowCasterManager.cpp Extends frame-time percentile fallback handling to non-positive counts.
src/Features/InverseSquareLighting.cpp Ensures calculated radii are finite and positive before use by attenuation callers.

@github-actions
Copy link
Copy Markdown

No actionable suggestions for changed features.

@alandtse alandtse changed the title fix(llf,isl): guard degenerate inputs in radius and shadow helpers fix(llf,isl): guard degenerate inputs helpers May 30, 2026
@alandtse alandtse merged commit 05d10c3 into dev May 30, 2026
21 checks passed
@github-actions
Copy link
Copy Markdown

✅ A pre-release build is available for this PR:
Download

@alandtse alandtse deleted the fix/llf-isl-degenerate-guards branch May 30, 2026 21:56
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