mercari / hcledit

Go package to edit HCL configuration
MIT License
44 stars 13 forks source link

Segmentation violation when file contains a block and an object #98

Open dmitry-g opened 8 months ago

dmitry-g commented 8 months ago

Hello, I encounter a segmentation fault when input file contains both block and object. Here is a simple example to reproduce the issue:

include {
  path = find_in_parent_folders()
}

inputs = {
  id = "123"
}
package main

import (
    "go.mercari.io/hcledit"
)

func main() {
    editor, _ := hcledit.ReadFile("config.hcl")

    key := "inputs.id"

    editor.Read(key)
}

Error message:

[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1021ee128]

goroutine 1 [running]:
go.mercari.io/hcledit/internal/ast.ReplaceBodyTokens(0x140000b89d8, {0x140000a2400, 0x6}, {0x140000fa320, 0xc, 0x1?})
    /Users/user/.asdf/installs/golang/1.21.0/packages/pkg/mod/go.mercari.io/hcledit@v0.0.9/internal/ast/ast.go:31 +0x1e8
go.mercari.io/hcledit/internal/walker.(*Walker).walkAttribute(0x14000163ec8, 0x140000b89d8, {0x140000d02e0, 0x2, 0x2}, 0x0, {0x102414400, 0x0, 0x0})
    /Users/user/.asdf/installs/golang/1.21.0/packages/pkg/mod/go.mercari.io/hcledit@v0.0.9/internal/walker/walker.go:81 +0x984
go.mercari.io/hcledit/internal/walker.(*Walker).Walk(0x1021f4210?, 0x49?, {0x140000d02e0, 0x2, 0x2}, 0x2a?, {0x102414400, 0x0, 0x0})
    /Users/user/.asdf/installs/golang/1.21.0/packages/pkg/mod/go.mercari.io/hcledit@v0.0.9/internal/walker/walker.go:26 +0x40
go.mercari.io/hcledit.(*HCLEditor).Read(0x14000134c60, {0x1021f4210, 0x9}, {0x0, 0x0, 0x140000021a0?})
    /Users/user/.asdf/installs/golang/1.21.0/packages/pkg/mod/go.mercari.io/hcledit@v0.0.9/hcledit.go:102 +0x16c
main.main()
    /Users/user/sites/golang/hclp/main_backup.go:12 +0x44
exit status 2

What I also noticed:

Thank you!

AshkanYarmoradi commented 4 months ago

Any Update on this topic?