Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when reading in invalid config.toml of module #9417

Closed
deining opened this issue Jan 23, 2022 · 7 comments
Closed

Panic when reading in invalid config.toml of module #9417

deining opened this issue Jan 23, 2022 · 7 comments

Comments

@deining
Copy link
Contributor

deining commented Jan 23, 2022

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.92.1-85E2E862+extended windows/amd64 BuildDate=2022-01-27T11:44:41Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes.

How to reproduce

At your command prompt, issue the following commands:

hugo new site github-issue-9417
cd github-issue-9417/
echo -n "[params" >> config.toml
hugo serve

Now, hugo panics:

$ hugo serve
hugo: collected modules in 1335 ms
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/pelletier/go-toml/v2.expect(...)
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/parser.go:1033
github.com/pelletier/go-toml/v2.(*parser).parseStdTable(0xc00068a230, {0xc000532000, 0x2, 0x202})
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/parser.go:198 +0x34a
github.com/pelletier/go-toml/v2.(*parser).parseTable(0x2030001, {0xc000532000, 0x2030001, 0x30001})
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/parser.go:146 +0x39
github.com/pelletier/go-toml/v2.(*parser).parseExpression(0x2de37b0, {0xc000532000, 0x235f05a4511, 0xb5d7e0})
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/parser.go:120 +0x9f
github.com/pelletier/go-toml/v2.(*parser).NextExpression(0xc00068a230)
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/parser.go:61 +0x119
github.com/pelletier/go-toml/v2.(*decoder).nextExpr(...)
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/unmarshaler.go:143
github.com/pelletier/go-toml/v2.(*decoder).fromParser(0xc000845d58, {0x26afd20, 0xc000006208, 0x3d0ab20})
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/unmarshaler.go:191 +0x65
github.com/pelletier/go-toml/v2.(*decoder).FromParser(0xc000845d58, {0x25ed620, 0xc000006208})
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/unmarshaler.go:177 +0xf8
github.com/pelletier/go-toml/v2.Unmarshal({0xc000532000, 0x2, 0x202}, {0x25ed620, 0xc000006208})
        /go/pkg/mod/github.com/pelletier/go-toml/[email protected]/unmarshaler.go:27 +0x112
github.com/gohugoio/hugo/parser/metadecoders.Decoder.UnmarshalTo({0x2e5c640, 0x0}, {0xc000532000, 0x0, 0xc000532000}, {0x28dbb68, 0x4}, {0x25ed620, 0xc000006208})
        /root/project/hugo/parser/metadecoders/decoder.go:159 +0x425
github.com/gohugoio/hugo/parser/metadecoders.Decoder.UnmarshalToMap({0x2e5c2c0, 0x0}, {0xc000532000, 0x2, 0x202}, {0x28dbb68, 0x4})
        /root/project/hugo/parser/metadecoders/decoder.go:67 +0xad
github.com/gohugoio/hugo/parser/metadecoders.Decoder.UnmarshalFileToMap({0x845f58, 0xc0}, {0x2e5c2c0, 0x3d6c440}, {0xc00003aa80, 0x24})
        /root/project/hugo/parser/metadecoders/decoder.go:84 +0xaa
github.com/gohugoio/hugo/config.loadConfigFromFile({0x2e5c2c0, 0x3d6c440}, {0xc00003aa80, 0xe9f5c5})
        /root/project/hugo/config/configLoader.go:86 +0x4a
github.com/gohugoio/hugo/config.FromFile({0x2e5c2c0, 0x3d6c440}, {0xc00003aa80, 0x24})
        /root/project/hugo/config/configLoader.go:61 +0x31
github.com/gohugoio/hugo/modules.(*collector).applyThemeConfig(0xc00069d5c0, 0xc0007fa2c0)
        /root/project/hugo/modules/collect.go:445 +0x388
github.com/gohugoio/hugo/modules.(*collector).add(0xc00069d5c0, 0xc0007fa160, {{0xc0000428e8, 0x14}, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...}, ...)
        /root/project/hugo/modules/collect.go:323 +0x985
github.com/gohugoio/hugo/modules.(*collector).addAndRecurse(0xc000262230, 0xc0007fa160, 0x0)
        /root/project/hugo/modules/collect.go:348 +0x1ec
github.com/gohugoio/hugo/modules.(*collector).collect(0xc00069d5c0)
        /root/project/hugo/modules/collect.go:522 +0x387
github.com/gohugoio/hugo/modules.(*Client).collect(0xc0006ad180, 0x19)
        /root/project/hugo/modules/collect.go:96 +0x79
github.com/gohugoio/hugo/modules.(*Client).Collect(0xc0006ad180)
        /root/project/hugo/modules/collect.go:69 +0x9f
github.com/gohugoio/hugo/hugolib.configLoader.collectModules({{0x2e5db50, 0xc00007d090}, {{0x2e5c2c0, 0x3d6c440}, {0x2e625d0, 0xc00069d1a0}, {0x0, 0x0}, {0xc00003f840, 0x16}, ...}}, ...)
        /root/project/hugo/hugolib/config.go:420 +0x510
github.com/gohugoio/hugo/hugolib.LoadConfig({{0x2e5c2c0, 0x3d6c440}, {0x2e625d0, 0xc00069d1a0}, {0x0, 0x0}, {0xc00003f840, 0x16}, {0xc00003f840, 0x16}, ...}, ...)
        /root/project/hugo/hugolib/config.go:148 +0xbbe
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig(0xc0004255e0)
        /root/project/hugo/commands/commandeer.go:309 +0x365
github.com/gohugoio/hugo/commands.newCommandeer(0x1, 0x1, 0x1, 0xc000425340, {0x2e0c840, 0xc000363f40}, 0xc00028fbc0, {0x0, 0x0, 0x0})
        /root/project/hugo/commands/commandeer.go:193 +0x310
github.com/gohugoio/hugo/commands.initializeConfig(0xd2, 0xee, 0xb3, 0x290eec0, {0x2e0c840, 0xc000363f40}, 0xc00061fc88)
        /root/project/hugo/commands/hugo.go:125 +0x31
github.com/gohugoio/hugo/commands.(*serverCmd).server(0xc000363f40, 0xc000176780, {0xc00061fcf0, 0x0, 0x0})
        /root/project/hugo/commands/server.go:242 +0x1ce
github.com/spf13/cobra.(*Command).execute(0xc000176780, {0x3d6ca08, 0x0, 0x0})
        /go/pkg/mod/github.com/spf13/[email protected]/command.go:856 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc00069f680)
        /go/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x3bc
github.com/gohugoio/hugo/commands.Execute({0xc0000963b0, 0x1, 0x1})
        /root/project/hugo/commands/hugo.go:92 +0xb4
main.main()
        /root/project/hugo/main.go:23 +0x58
@bep
Copy link
Member

bep commented Jan 28, 2022

This is an upstream issue. I will update the TOML library; if that doesn't work, please file an issue at https://github.com/pelletier/go-toml/issues

@bep bep added this to the v0.93.0 milestone Jan 28, 2022
@bep
Copy link
Member

bep commented Jan 28, 2022

See #9439

@jmooring
Copy link
Member

With v0.92.0 I am unable to reproduce the panic as described.

git clone --single-branch -b hugo-github-issue-9417 https://github.com/jmooring/hugo-testing hugo-github-issue-9417
cd hugo-github-issue-9417
cd test-site
hugo server

Error: "/home/jmooring/temp/hugo-github-issue-9417/test-module/config.toml:1:3": unmarshal failed: toml: expected character U+005D

@deining
Copy link
Contributor Author

deining commented Jan 28, 2022

With v0.92.0 I am unable to reproduce the panic as described.

Inside your file test-module/config.toml there is a newline at the end of the first line. Remove this newline so that you have one single line only, and you will be confronted with the panic.
I updated my post so that this gets reflected.

@jmooring
Copy link
Member

jmooring commented Jan 28, 2022

@deining I updated the example and can reproduce the problem. The fact that your invalid config.toml file exists in a module is irrelevant. The panic occurs when unmarshaling any TOML file where the last line1 contains an incomplete key (example: [params) and does not end with a newline.

@bep I confirm that this is resolved with #9440. No panic, and the error is:

unmarshal failed: toml: expected character ] but the document ended here

Footnotes

  1. I use the term "line" loosely because, by POSIX standards, it isn't a line. See definition.

@deining
Copy link
Contributor Author

deining commented Jan 29, 2022

@deining I updated the example and can reproduce the problem.

Great.

The fact that your invalid config.toml file exists in a module is irrelevant.

You are right. I updated my initial post with instructions how to reproduce the problem quickly.

@bep I confirm that this is resolved with #9440. No panic, and the error is:

unmarshal failed: toml: expected character ] but the document ended here

Glad to see that the issue was fixed upstream already.

@bep bep closed this as completed in 5ca40c8 Jan 29, 2022
@github-actions
Copy link

github-actions bot commented Feb 6, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants