Skip to content

fix(diagram): initialize operand id on unmatched PlantUML openers (#2818) - #2832

Closed
divakantpandey wants to merge 1 commit into
DeusData:mainfrom
divakantpandey:fix/2818-plantuml-operand-uninitialized-id
Closed

divakantpandey wants to merge 1 commit into
DeusData:mainfrom
divakantpandey:fix/2818-plantuml-operand-uninitialized-id

Conversation

@divakantpandey

Copy link
Copy Markdown
Contributor

Fixes #2818

Problem

When indexing PlantUML sequence diagrams that contain messages to or from diagram edges (Alice ->: msg, Alice <-: msg, [-> Alice: msg, [<- Alice: msg), dg_puml_operand() receives an opener character without a matching closer.

dg_puml_operand() initialized *label = dg_s(NULL, 0); at its entry, but only wrote *id on success paths. On unmatched openers, if (!c) return i; returned early without writing *id. In callers dg_puml_relation() and dg_puml_decl(), lid, rid, id, and aid were uninitialized stack variables, causing if (!rid.n) to read stack garbage and pass unmapped addresses into dg_element() and dg_trim(), crashing the index worker with SIGSEGV.

Solution

• In dg_puml_operand(), initialize *id = dg_s(NULL, 0); at entry alongside *label.
• Zero-initialize lid, llab, rid, and rlab in dg_puml_relation(), and id, label, aid, and alab in dg_puml_decl().

Verification

• Added diagrams_plantuml_edge_messages_issue2818 in tests/test_diagrams.c.
• Verified failure toggle: reproduces deterministically under ASan+UBSan prior to fix (AddressSanitizer: global-buffer-overflow in dg_id_key from dg_element), passes cleanly after fix.
• ./scripts/test.sh --suites diagrams: 19/19 passed.
• ./scripts/test.sh --contracts-only: All static contract steps passed.
• ./scripts/check-dco.sh upstream/main..HEAD: Valid DCO sign-off verified.
• ./scripts/build.sh: Production binary builds cleanly.

…usData#2818)

dg_puml_operand initialized *label at entry but only assigned *id on successful matches. When an opener character (':', '[', '(', '"') lacks a matching closer, dg_puml_operand returns early without writing *id, leaving caller stack variables uninitialized.

In dg_puml_relation and dg_puml_decl, this caused the !rid.n / !id.n checks to evaluate uninitialized stack memory, passing garbage pointers into dg_element and dg_trim, which crashed the index worker with a segmentation fault on PlantUML sequence edge messages ('Alice ->: msg', '[-> Alice: msg').

Initialize *id at the top of dg_puml_operand alongside *label, and zero-initialize the caller operand variables in dg_puml_relation and dg_puml_decl.

Fixes DeusData#2818

Signed-off-by: Divakant Pandey <divakant01@gmail.com>
@github-actions

Copy link
Copy Markdown

Thanks for opening this — it has been seen, and it is queued.

This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence.

Current review status: working through a backlog. 0.9.1-rc.1 is out, so the release freeze that held reviews is over — but it left a large queue of open pull requests behind it, and we are reading through them oldest-first. The background is in discussion #1144.

What that means for this PR, concretely:

  • It will not be closed for inactivity. No stale bot touches pull requests here.
  • It may still sit a while before a human reads it. That is on us, not on you.
  • Older PRs are read first, so a recent one is not being skipped — it is behind a queue.

Things that will genuinely speed it up whenever review does happen:

  • Keep it rebased on main — the tree is moving quickly right now, and a conflicting branch cannot be reviewed as the diff you intended.
  • Get CI green, or say which failures you believe are pre-existing.
  • Keep the change to one claim. Bundled features and refactors get split before they get merged, which costs you a round trip.
  • Every commit needs a sign-off (git commit -s) — CI enforces DCO.

If this fixes a bug, a reproduction we can run is worth more than a description of the symptom.

Thanks for contributing, and sorry in advance for the wait.

@DeusData

Copy link
Copy Markdown
Owner

Thank you very much, @divakantpandey, for jumping on #2818 so quickly and for the clear write-up -- your diagnosis matches the root cause exactly, and your test reproduces the crash on main.

#2827 was opened a few hours earlier with the same one-line fix in dg_puml_operand, and it has now landed in 76dda7e with a test that also covers the unclosed-declaration path. Since both pull requests carry the same production change, we are closing this one as a duplicate rather than landing the fix twice; the extra zero-initializations in the callers are not needed once dg_puml_operand always writes both outputs.

This is no reflection on your work -- it was simply a race on a fresh issue. Thank you again; #2822 and #2833 are in the queue.

@DeusData DeusData closed this Oct 31, 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.

Index worker segfaults on PlantUML edge messages: dg_puml_operand leaves *id uninitialized

2 participants