Skip to content

hardening(ui): drop unbounded GLSL sink + stop WebGL-context rebuild on uniform tweaks (#11088)#11102

Merged
lalalune merged 1 commit into
developfrom
fix/11088-glsl-background-hardening
Jul 2, 2026
Merged

hardening(ui): drop unbounded GLSL sink + stop WebGL-context rebuild on uniform tweaks (#11088)#11102
lalalune merged 1 commit into
developfrom
fix/11088-glsl-background-hardening

Conversation

@lalalune

@lalalune lalalune commented Jul 2, 2026

Copy link
Copy Markdown
Member

GLSL background hardening (#11088, follow-up to #11083)

Two latent hardening fixes from the post-merge review of the programmable shader background. No rendered-output change → visual audit N/A (Fix 1 removes an unreachable path; Fix 2 renders byte-identically, just without a context teardown).

Fix 1 — drop the unbounded raw-GLSL sink (defense-in-depth)

useBackgroundApplyChannel accepted a raw source field from any background:apply broadcaster (explicitSource). The static gate bans while/do and caps size but does not bound for-loop counts, so a crafted for(int i=0;i<200000;i++) slips past the gate + GL compile and stalls the GPU for one pathological frame (the frame-time watchdog needs 5 consecutive slow frames — the first freezes first).

Fix: drop the explicitSource branch entirely — presets are the only source of shader code, so raw text has no path to the compiler. Confirmed no shipped caller broadcasts a raw source field (grep). This is the cleaner root fix (remove the surface) vs. a for-loop heuristic.

Fix 2 — stop rebuilding the WebGL context on uniform-only tweaks (perf)

The single build effect was keyed [source, uniforms, color], so a uniform-only tweak tore down + rebuilt the THREE.WebGLRenderer + WebGL context and recompiled the shader (browsers cap ~16 live contexts → churn + GC pressure).

Fix: split into a heavy build/compile effect keyed on source only (compiling against uniformsRef/colorRef current values) + a lightweight effect keyed on [uniforms, color] that mutates uniformDefs.u_*.value in place (with a uniformsEqual short-circuit and a reduced-motion static repaint). The running rAF loop picks up the new values next frame.

Evidence (fail-without-fix)

  • ProgrammableShaderBackground.rebuild.test.tsx (THREE mocked; counts renderer constructions): a uniform/color-only change keeps rendererCount === 1 and mutates the live uniform in place; a source change rebuilds. Reverting the dep-split → 2 tests fail (rendererCount climbs on tweak). Independently re-verified.
  • useBackgroundApplyChannel.test.tsx: the raw-source path is no longer accepted.
  • 9 tests pass; uniformsEqual export + u_color Vector3 type verified.

Refs #11088 #11083 #10694

🤖 Generated with Claude Code

…on uniform tweaks (#11088)

Fix 1: useBackgroundApplyChannel no longer accepts raw GLSL text via the
payload 'source' field — presets are the only source of shader code, so a
crafted bounded-for GPU bomb (which passes the static gate + GL compile)
has no path to the compiler. No shipped broadcaster ever sent 'source'
(plugin-app-control sends preset ids only), so the branch was dead but
dangerous.

Fix 2: ProgrammableShaderBackground splits its single effect. The heavy
renderer-build/compile effect is keyed on 'source' only; a separate light
effect mutates live uniformDefs.u_*.value (and u_color) in place on
uniform/color changes, repainting the static frame under reduced motion.
Uniform tweaks no longer tear down the WebGL context (browsers cap ~16
live contexts) or recompile the shader; rendering output is identical.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 21ae96f3-64a2-4d32-8611-276de53fa2a9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/11088-glsl-background-hardening

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.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

❌ PR title does not match the required pattern. Please use one of these formats:

  • 'type: description' (e.g., 'feat: add new feature')
  • 'type(scope): description' (e.g., 'chore(core): update dependencies')
    Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, release

@claude

claude Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

@github-actions github-actions Bot added the ui label Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant