status-im / nim-toml-serialization

Flexible TOML serialization [not] relying on run-time type information.
Apache License 2.0
35 stars 8 forks source link

Segfault on `orc` when echo'ing decoded object #62

Closed HugoGranstrom closed 1 year ago

HugoGranstrom commented 1 year ago

When decoding an object on orc it segfaults when echoing the object. It works for refc but not on orc (tested on 1.6.10 and devel). Reproducing code:

import toml_serialization

type NbConfig* = object
  srcDir*, homeDir*: string

let f = readFile("nimib.toml")

let t = Toml.decode(f,  NbConfig, "nimib")

echo t # error here

nimib.toml:

[nimib]
srcDir = "docsrc"
homeDir = "docs"

Output:

Traceback (most recent call last)
/home/hugo/code/nim/nimib/x_toml.nim(10) x_toml
/home/hugo/.choosenim/toolchains/nim-#devel/lib/std/private/miscdollars.nim(25) $
/home/hugo/.choosenim/toolchains/nim-#devel/lib/system/alloc.nim(1043) alloc
/home/hugo/.choosenim/toolchains/nim-#devel/lib/system/alloc.nim(859) rawAlloc
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)

Expected output:

(srcDir: "docsrc", homeDir: "docs")
jangko commented 1 year ago

Thank you for reporting this, this is actually a severe bug[s] in Nim when orc enabled. Somehow var param stop working after certain depth of indirect recursion.

This bug have not reported to Nim dev team because it is very hard to isolate and reproduce outside nim-serialization framework. But because it has appear consistently in several nim-serialization derived libraries, I think it's time to look deeper into this.

For the time being, you can stick with refc that what we also doing because orc breaks a lot of our libraries.