Description
When testing for MB-32619, I identified a key generator which would cause cbimport to panic.
The command and stack trace is shown below:
/opt/couchbase/bin/cbimport json -c couchbase://localhost -u Administrator -p password -b travel-sample -d file://output.json -f lines -g 'Matt#MONO_INCR#%%sad'
|
panic: runtime error: slice bounds out of range
|
|
goroutine 1 [running]:
|
github.com/couchbase/backup/utils/keygen.CreateKeyGenerator(0x7ffdec169948, 0x15, 0x79c666, 0xc420182040, 0x0)
|
goproj/src/github.com/couchbase/backup/utils/keygen/key_gen.go:114 +0x613
|
github.com/couchbase/backup/jsondata.CreateJsonSource(0x7ffdec169929, 0x12, 0x7ffdec16993f, 0x5, 0x7ffdec169948, 0x15, 0x7ffdec169918, 0xd, 0x0, 0x0, ...)
|
goproj/src/github.com/couchbase/backup/jsondata/source.go:83 +0x363
|
github.com/couchbase/backup.JsonToCouchbaseTransferable(0xc42014b120, 0x15, 0x7ffdec1698fb, 0xd, 0x7ffdec16990c, 0x8, 0x7ffdec169918, 0xd, 0x7ffdec169929, 0x12, ...)
|
goproj/src/github.com/couchbase/backup/transferable.go:198 +0x22e
|
main.(*JsonContext).Run(0xc420070f70)
|
goproj/src/github.com/couchbase/backup/cmd/cbimport/json.go:62 +0x45e
|
main.(*JsonContext).Run-fm()
|
goproj/src/github.com/couchbase/backup/cmd/cbimport/main.go:239 +0x2a
|
github.com/couchbase/cbflag.(*Command).parseFlags(0xc420161ea0, 0xc4200ebbf8, 0xc42000a620, 0xe, 0xe)
|
godeps/src/github.com/couchbase/cbflag/command.go:223 +0x3a4
|
github.com/couchbase/cbflag.(*Command).parse(0xc420161ea0, 0xc4200ebbf8, 0xc42000a620, 0xe, 0xe)
|
godeps/src/github.com/couchbase/cbflag/command.go:92 +0xf1
|
github.com/couchbase/cbflag.(*Command).parseCommands(0xc420161f10, 0xc4200ebbf8, 0xc42000a610, 0xf, 0xf)
|
godeps/src/github.com/couchbase/cbflag/command.go:104 +0x326
|
github.com/couchbase/cbflag.(*Command).parse(0xc420161f10, 0xc4200ebbf8, 0xc42000a610, 0xf, 0xf)
|
godeps/src/github.com/couchbase/cbflag/command.go:90 +0x120
|
github.com/couchbase/cbflag.(*CLI).Parse(0xc420016120, 0xc42000a600, 0x10, 0x10)
|
godeps/src/github.com/couchbase/cbflag/cli.go:59 +0x1cc
|
main.main()
|
goproj/src/github.com/couchbase/backup/cmd/cbimport/main.go:414 +0x3c4d
|
Looks the crash is at https://github.com/couchbase/backup/blob/0019e7f84870b03329ebdeab25d92681fd2c35eb/utils/keygen/key_gen.go#L114 - again looks like an escaped '%' is not handled correctly, so it tries to perform the field substitution even though the string it's handling is '%%', which should just become '%' after processing.