stores/ini - Block style comments fail to decrypt
Open
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 23.1k
- Forks
- 1.1k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 9
Description
An ini file with a block style comment such as the one below will fail to decrypt.
;;;;;;;;;;;;;;;;;
; block comment ;
;;;;;;;;;;;;;;;;;
[foo]
foo = 1
Encrypting appears to work fine. However, decrypting yields:
$ sops -d test.sops.ini
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
gopkg.in/ini%2ev1.(*File).writeToBuffer(0xc00001e0b0, 0x0, 0x0, 0x1ba0b20, 0xc00001e101, 0xc00043c3f0)
/Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/gopkg.in/ini.v1@v1.44.0/file.go:247 +0x1432
gopkg.in/ini%2ev1.(*File).WriteToIndent(0xc00001e0b0, 0x1e11440, 0xc00043c3f0, 0x0, 0x0, 0xc00015c460, 0x0, 0x0)
/Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/gopkg.in/ini.v1@v1.44.0/file.go:391 +0x45
gopkg.in/ini%2ev1.(*File).WriteTo(...)
/Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/gopkg.in/ini.v1@v1.44.0/file.go:400
go.mozilla.org/sops/v3/stores/ini.Store.encodeTree(0xc000417980, 0x1, 0x1, 0x0, 0x0, 0xc000417980, 0x1, 0x1)
/private/tmp/sops-20200914-69820-1n7esxf/sops-3.6.1/stores/ini/store.go:62 +0x10a
go.mozilla.org/sops/v3/stores/ini.Store.iniFromTreeBranches(...)
/private/tmp/sops-20200914-69820-1n7esxf/sops-3.6.1/stores/ini/store.go:89
go.mozilla.org/sops/v3/stores/ini.(*Store).EmitPlainFile(0x2428c20, 0xc000417980, 0x1, 0x1, 0x0, 0x1e1de60, 0xc0003a3ef0, 0xc000036540, 0x20)
/private/tmp/sops-20200914-69820-1n7esxf/sops-3.6.1/stores/ini/store.go:307 +0x4a
main.decrypt(0x1e1de60, 0xc0003a3ef0, 0x36ca138, 0x2428c20, 0x36ca138, 0x2428c20, 0xc0000428a0, 0x54, 0x0, 0x0, ...)
/private/tmp/sops-20200914-69820-1n7esxf/sops-3.6.1/cmd/sops/decrypt.go:47 +0x262
main.main.func8(0xc00016cc60, 0x0, 0x0)
/private/tmp/sops-20200914-69820-1n7esxf/sops-3.6.1/cmd/sops/main.go:769 +0x2a05
gopkg.in/urfave/cli%2ev1.HandleAction(0x1acfda0, 0x1cc4470, 0xc00016cc60, 0x0, 0x0)
/Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/gopkg.in/urfave/cli.v1@v1.20.0/app.go:490 +0x82
gopkg.in/urfave/cli%2ev1.(*App).Run(0xc000345d40, 0xc0000321b0, 0x3, 0x3, 0x0, 0x0)
/Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/gopkg.in/urfave/cli.v1@v1.20.0/app.go:264 +0x5f5
main.main()
/private/tmp/sops-20200914-69820-1n7esxf/sops-3.6.1/cmd/sops/main.go:933 +0x3525
I was able to reproduce with something as simple as this:
;;
; comment
[foo]
foo = 1
Seems having the two or more colons followed by a line with another comment triggers it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in stores/ini/store.go, especially encodeTree and iniFromTreeBranches, and reproduce the panic with the block-comment INI examples from the issue. Trace how the INI dependency handles consecutive comment lines during decryption. Done means the example decrypts successfully without an index-out-of-range panic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100