[PR #4985] [MERGED] fix: linearize residual content parsers #6569

Closed
opened 2026-10-23 04:11:40 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4985
Author: @SpicyMarinara
Created: 8/13/2026
Status: ✅ Merged
Merged: 8/13/2026
Merged by: @SpicyMarinara

Base: staging ← Head: agent/code-scanning-residuals


📝 Commits (8)

  • 48e2e99 fix: linearize residual content parsers
  • 2284fdf fix: preserve nested character macro detection
  • f89a28c fix: keep conditional macro detection linear
  • 9df97ce test: isolate group macro expansion
  • b7cabfc fix: parse nested macro conditions in one pass
  • 96d3232 perf: scan macro word operators in place
  • 97d36b6 fix: preserve malformed macro condition behavior
  • a4827a2 refactor: align conditional macro analysis

📊 Changes

4 files changed (+575 additions, -150 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/game/segment-edits.ts (+2 -2)
📝 packages/shared/src/utils/macro-engine.ts (+451 -146)
📝 scripts/regressions/code-scanning-content-parsing.regression.ts (+121 -2)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.

Linked issue

Closes #4984

Why this change

  • CodeQL identified two polynomial-time parsing paths reachable from generated or user-authored text. Large malformed inputs could stall the local server.
  • The fix must preserve valid inline VN dialogue syntax and grouped character macros without imposing content-size caps.

What changed

  • Constrained inline VN dialogue normalization to single-line, non-nested tag grammar.
  • Replaced the character-macro detection regex with the existing balanced macro and conditional parsers.
  • Added behavior and adversarial timing regressions for both paths.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Automated proof: pnpm regression:code-scanning-security
  • Automated proof: git diff --check
  • Manually verify a Game response containing inline [Speaker] [main]: dialogue and a multi-character bracketed macro block before release.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] <paths> follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

  • Not applicable; this changes backend/shared text parsing only.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of malformed or very large generated text in inline game dialogue and group character macros.
    • Preserved responsiveness for nested, conditional, case-insensitive, and whitespace-tolerant macro expressions.
    • Prevented dialogue parsing from crossing line breaks or incorrectly consuming brackets.
    • Ensured valid authored content remains unrestricted.
  • Tests

    • Added regression coverage for formatting, content replacement, macro expansion, malformed input, and adversarial parsing scenarios.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/4985 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 8/13/2026 **Status:** ✅ Merged **Merged:** 8/13/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `agent/code-scanning-residuals` --- ### 📝 Commits (8) - [`48e2e99`](https://github.com/Pasta-Devs/Marinara-Engine/commit/48e2e99e9a118fcdcc374dbbb283f75a3cd05c3b) fix: linearize residual content parsers - [`2284fdf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2284fdf6979b82ac78ea92e164857814dbb5f51c) fix: preserve nested character macro detection - [`f89a28c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f89a28cbe302727e04a9d4c01b87e9c6ca805aa4) fix: keep conditional macro detection linear - [`9df97ce`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9df97cefc07f664dfb62044a06550e21b4af24e1) test: isolate group macro expansion - [`b7cabfc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b7cabfc799e2d57b22fef2a6fd257409a44f2b75) fix: parse nested macro conditions in one pass - [`96d3232`](https://github.com/Pasta-Devs/Marinara-Engine/commit/96d3232191fb3c2e35374f1469c842830b87d448) perf: scan macro word operators in place - [`97d36b6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/97d36b6f77f0a992aa5e76ab167f760dd0c6d141) fix: preserve malformed macro condition behavior - [`a4827a2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a4827a248e15180ade46ef72badff58dbc2bc049) refactor: align conditional macro analysis ### 📊 Changes **4 files changed** (+575 additions, -150 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/game/segment-edits.ts` (+2 -2) 📝 `packages/shared/src/utils/macro-engine.ts` (+451 -146) 📝 `scripts/regressions/code-scanning-content-parsing.regression.ts` (+121 -2) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Closes #4984 ## Why this change - CodeQL identified two polynomial-time parsing paths reachable from generated or user-authored text. Large malformed inputs could stall the local server. - The fix must preserve valid inline VN dialogue syntax and grouped character macros without imposing content-size caps. ## What changed - Constrained inline VN dialogue normalization to single-line, non-nested tag grammar. - Replaced the character-macro detection regex with the existing balanced macro and conditional parsers. - Added behavior and adversarial timing regressions for both paths. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Automated proof: `pnpm regression:code-scanning-security` - Automated proof: `git diff --check` - Manually verify a Game response containing inline `[Speaker] [main]:` dialogue and a multi-character bracketed macro block before release. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n] <paths>` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) - Not applicable; this changes backend/shared text parsing only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of malformed or very large generated text in inline game dialogue and group character macros. * Preserved responsiveness for nested, conditional, case-insensitive, and whitespace-tolerant macro expressions. * Prevented dialogue parsing from crossing line breaks or incorrectly consuming brackets. * Ensured valid authored content remains unrestricted. * **Tests** * Added regression coverage for formatting, content replacement, macro expansion, malformed input, and adversarial parsing scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:11:40 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6569
No description provided.