typst icon indicating copy to clipboard operation
typst copied to clipboard

Stack overflow in list grouping with linebreak

Open AliothCancer opened this issue 10 months ago โ€ข 9 comments

Description

version: typst 0.14.2 (b33de9de) OS: Endeavour Os

I apologize for the generic title, but I just wrote some typst and got a sigsegv when compiling this code:

#show list: it => {
  for item in it.children{
    [#item\ ]
  }
}

- One

If \ is removed the output is error: maximum grouping depth exceeded

Reproduction URL

No response

Operating system

No response

Typst version

  • [ ] I am using the latest version of Typst

AliothCancer avatar Feb 03 '26 14:02 AliothCancer

Hello @AliothCancer , I created a PR for this issue fixing. Could you please review my updates? Thanks

speedcoder430 avatar Feb 23 '26 09:02 speedcoder430

Hello @AliothCancer , I created a PR for this issue fixing. Could you please review my updates? Thanks

Firstly I want to say that this is my first time doing this, in general I'm newbie so I hope you can guide me if necessary.

I git cloned https://github.com/speedcoder430/typst/tree/refs/heads/fix-list-grouping-stack-overflow and ran cargo build --release then I tried to compile the typst code above and got this:

# version
typst on ๎‚  main [?] is ๐Ÿ“ฆ v0.14.2 via ๐Ÿฆ€ v1.92.0 via t v0.14.2
โฏ ./target/release/typst -V
typst 0.14.2 (88356d0b)

typst on ๎‚  main [?] is ๐Ÿ“ฆ v0.14.2 via ๐Ÿฆ€ v1.92.0 via t v0.14.2
โฏ ./target/release/typst compile testing_escape_in_list_grouping.typ

thread 'main' (20281) has overflowed its stack
fatal runtime error: stack overflow, aborting
Error: nu::shell::core_dumped

  ร— External command core dumped
   โ•ญโ”€[entry #12:1:1]
 1 โ”‚ ./target/release/typst compile testing_escape_in_list_grouping.typ
   ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   ยท            โ•ฐโ”€โ”€ core dumped with SIGABRT (6)
   โ•ฐโ”€โ”€โ”€โ”€

Note: I actually don't remember if I installed typst through cargo binstall or if I've compiled it.

For reference the typst binary I've installed from cargo outputs this:

typst on ๎‚  main [?] is ๐Ÿ“ฆ v0.14.2 via ๐Ÿฆ€ v1.92.0 via t v0.14.2
โฏ typst -V
typst 0.14.2 (b33de9de)

typst on ๎‚  main [?] is ๐Ÿ“ฆ v0.14.2 via ๐Ÿฆ€ v1.92.0 via t v0.14.2
โฏ typst compile testing_escape_in_list_grouping.typ
Error: nu::shell::core_dumped

  ร— External command core dumped
   โ•ญโ”€[entry #14:1:1]
 1 โ”‚ typst compile testing_escape_in_list_grouping.typ
   ยท โ”€โ”€โ”ฌโ”€โ”€
   ยท   โ•ฐโ”€โ”€ core dumped with SIGSEGV (11)
   โ•ฐโ”€โ”€โ”€โ”€

AliothCancer avatar Feb 23 '26 13:02 AliothCancer

Hi @AliothCancer , thanks for taking the time to test this!

It looks like you accidentally built from the main branch instead of the fix branch. The version hash in your output (88356d0b) matches main's HEAD, not the fix commit (835f266).

This likely happened because git clone doesn't understand the /tree/refs/heads/... path in the GitHub URL โ€” it just clones the default branch.

To test the fix branch, you can run:

git clone https://github.com/speedcoder430/typst.git
cd typst
git checkout fix-list-grouping-stack-overflow
cargo build --release
./target/release/typst compile testing_escape_in_list_grouping.typ

With the fix, instead of a stack overflow crash, you should see:

error: maximum grouping depth exceeded

Let me know if it works after switching to the correct branch. Thanks again.

speedcoder430 avatar Feb 23 '26 13:02 speedcoder430

Thanks for guiding me, so here the fixed branch:

typst on ๎‚  fix-list-grouping-stack-overflow [?] is ๐Ÿ“ฆ v0.14.2 via ๐Ÿฆ€ v1.92.0 via t v0.14.2
โฏ ./target/release/typst compile testing_escape_in_list_grouping.typ
error: maximum grouping depth exceeded
  โ”Œโ”€ testing_escape_in_list_grouping.typ:7:0
  โ”‚
7 โ”‚ - One
  โ”‚ ^^^^^

AliothCancer avatar Feb 23 '26 13:02 AliothCancer

It seems the updates are working properly. Now can you approve the PR? https://github.com/typst/typst/pull/7903

speedcoder430 avatar Feb 23 '26 13:02 speedcoder430

I went to https://github.com/typst/typst/pull/7903 and I can click on "Submit comments" I can only write a comment, I cannot click on "Approve", so should I just leave a comment:

"Tested locally on EndeavourOS using the reproduction code from the original issue. The crash is gone and the compiler now correctly returns error: maximum grouping depth exceeded instead of overflowing the stack. Thank you."

?

AliothCancer avatar Feb 23 '26 13:02 AliothCancer

That's great for me. I hope the project owner can check your feedback as well. Thanks for your help.

speedcoder430 avatar Feb 23 '26 14:02 speedcoder430

Done, cool! You're welcome, this is actually the very first time I do this, I hope your PR will be approved.

AliothCancer avatar Feb 23 '26 14:02 AliothCancer

Done, cool! You're welcome, this is actually the very first time I do this, I hope your PR will be approved.

Thanks

speedcoder430 avatar Feb 23 '26 14:02 speedcoder430