zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
27.2k stars 1.9k forks source link

invalid mermaid diagram will crash trilium #2231

Open raphwriter opened 3 years ago

raphwriter commented 3 years ago

Version used: 0.48.0-beta & 0.48.1-beta Description: Entering invalid diagram code in a mermaid git diagram potentially causes serious issues.

Steps to reproduce:

  1. create git diagram
  2. add steps to diagram:
  3. ...
  4. branch new1
  5. checkout new1
  6. commit
  7. checkout new2 <-- note: branch new2 was never created
  8. ...

These steps caused trilium to stop responding, resulting in Firefox warning me about a script which is slowing down the browser etc... Not even reloading the page helps as the most recently used note will be opened by default after login.

Workaround (for server instance at least):

  1. open trilium with appending "/login" at the URL
  2. quickly close the note containing the corrupt diagram

2021-10-14.log

sigaloid commented 3 years ago

Can replicate this, but the log you uploaded is empty.

Script terminated by timeout at:
Bw@https://test.matthew.science/#root/7GItoUdGQIbF/6SnGwcINjClA/Xp7qG5wVOz4D-j4Bx line 2 > injectedScript:26:703794
Rw@https://test.matthew.science/#root/7GItoUdGQIbF/6SnGwcINjClA/Xp7qG5wVOz4D-j4Bx line 2 > injectedScript:26:704969
render@https://test.matthew.science/#root/7GItoUdGQIbF/6SnGwcINjClA/Xp7qG5wVOz4D-j4Bx line 2 > injectedScript:26:802043
**refreshWithNote@https://test.matthew.science/app/widgets/mermaid.js:74:32**
async*refresh@https://test.matthew.science/app/widgets/note_context_aware_widget.js:47:24
entitiesReloadedEvent@https://test.matthew.science/app/widgets/mermaid.js:85:24
callMethod@https://test.matthew.science/app/widgets/component.js:86:29
handleEvent/<@https://test.matthew.science/app/widgets/component.js:46:46
promise callback*handleEvent@https://test.matthew.science/app/widgets/component.js:46:30
handleEventInChildren@https://test.matthew.science/app/widgets/component.js:61:33
handleEvent@https://test.matthew.science/app/widgets/component.js:47:18
handleEventInChildren@https://test.matthew.science/app/widgets/component.js:61:33
handleEventInChildren@https://test.matthew.science/app/widgets/containers/split_note_container.js:138:26
handleEvent@https://test.matthew.science/app/widgets/component.js:47:18
handleEventInChildren@https://test.matthew.science/app/widgets/component.js:61:33
handleEvent@https://test.matthew.science/app/widgets/component.js:47:18
handleEventInChildren@https://test.matthew.science/app/widgets/component.js:61:33
handleEvent@https://test.matthew.science/app/widgets/component.js:47:18
handleEventInChildren@https://test.matthew.science/app/widgets/component.js:61:33
handleEvent@https://test.matthew.science/app/widgets/component.js:47:18
handleEventInChildren@https://test.matthew.science/app/widgets/component.js:61:33
handleEvent@https://test.matthew.science/app/widgets/component.js:47:18
handleEventInChildren@https://test.matthew.science/app/widgets/component.js:61:33
handleEvent@https://test.matthew.science/app/widgets/component.js:47:18
triggerEvent@https://test.matthew.science/app/services/app_context.js:84:21
processEntityChanges@https://test.matthew.science/app/services/froca_updater.js:77:26
async*consumeFrontendUpdateData@https://test.matthew.science/app/services/ws.js:164:48
executeFrontendUpdate@https://test.matthew.science/app/services/ws.js:88:35
handleMessage@https://test.matthew.science/app/services/ws.js:112:15

Which is weird, because https://github.com/zadam/trilium/blob/master/src/public/app/widgets/mermaid.js#L73 is wrapped in a try catch.

Okay, so mermaid.parse(content) should return a boolean on valid mermaid markdown, so maybe change the try catch to that.

sigaloid commented 3 years ago

Welp. It crashes in the Mermaid live editor as well. Not even an error, just the site crashes. This seems to be an issue with Mermaid entirely. Unless somehow that can be parsed with mermaid.parse which is still a WIP according to https://github.com/mermaid-js/mermaid/issues/1066.

Try pasting in

gitGraph:
options
{
    "nodeSpacing": 150,
    "nodeRadius": 10
}
end
commit
branch newbranch
checkout newbranch
commit
commit
checkout master
commit
commit
merge newbranch

then changing any branch name.