mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2424] [MERGED] Bound macro variable expansion and dice roll resource use #5600
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5600
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2424
Author: @Romuromylus
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/macro-resource-bounds📝 Commits (1)
2aa6b7bBound macro variable expansion and dice roll resource use📊 Changes
1 file changed (+40 additions, -7 deletions)
View changed files
📝
src/engine/shared/macros/macro-engine.ts(+40 -7)📄 Description
Linked issue
Closes #2363
Why this change
{{roll:NdM}}loop, an unclamped{{random:X:Y}}range, and setvar/addvar value re-expansion against shared mutablectx.variables. A billion-laughs{{addvar::z::{{getvar::z}}}}chain could OOM the renderer; a hostile{{roll:999999999d6}}could freeze it.What changed
src/engine/shared/macros/macro-engine.ts:MAX_TOTAL_VARIABLE_SIZE) and an expansion-recursion cap (MAX_VARIABLE_EXPANSION_DEPTH = 8) throughMacroResolutionState; setvar/addvar bail gracefully (return"", no throw, prior writes preserved) once over budget/depth.{{roll:NdM}}count (MAX_DICE_ROLL_COUNT = 10_000) and sides (MAX_DICE_SIDES = 1_000_000).{{random:X:Y}}span (MAX_RANDOM_RANGE = 1_000_000) and fixes a latent inverted-range underflow (hi = Math.max(lo, …)).{{cb1}}…{{cbN}}variable assembly (a few KB per block) still resolves fully.Refactor impact
Primary owner: engine generation (shared macros)
Impact areas reviewed:
src/engine/shared/macros/macro-engine.ts(resolveMacrosWithState,MacroResolutionState)Boundary notes:
variableExpansionDepthfield is optional so existing{ characterFieldDepth }constructors stay valid. The web build'spackages/sharedcopy is a separate repo/topology and intentionally out of scope.Pressure points touched:
Validation
pnpm checkpasses before PR push/handoffManual verification notes
pnpm vitest run(macro-engine) — local-only tests confirmed: a billion-laughs doubling chain is bounded near 1MB and returns in <5s (was multi-GB OOM);{{roll:999999999d6}}clamps to 10000 and returns promptly;{{random:10:5}}no longer underflows; and a 3×50KB Celia-style assembly still resolves fully (cap is generous).{{roll:2d6}}regression case unchanged.pnpm exec tsc -bandpnpm exec eslint …macro-engine.ts— clean.Feature Discoverability
src/features/shell/discovery/Reason:
Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.