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

Array merge example SIGSEGV #1096

Closed
splitice opened this issue Feb 8, 2022 · 2 comments
Closed

Array merge example SIGSEGV #1096

splitice opened this issue Feb 8, 2022 · 2 comments
Labels

Comments

@splitice
Copy link

splitice commented Feb 8, 2022

Tried the array merge example from this repository, it immediately crashed.

$ yq ea '((.[] | {.name: .}) as $item ireduce ({}; . * $item )) as $uniqueMap  | ( $uniqueMap  | to_entries | .[]) as $item ireduce([]; . + $item.value)' 1.yaml 2.yaml
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x672c14]

goroutine 1 [running]:
container/list.(*List).Len(...)
        /opt/hostedtoolcache/go/1.17.6/x64/src/container/list/list.go:66
github.com/mikefarah/yq/v4/pkg/yqlib.reduceOperator(0xc0000897d0, {0xc000302fc0, 0x0, 0x2}, 0xc00027ae10)
        /home/runner/work/yq/yq/pkg/yqlib/operator_reduce.go:27 +0x114
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x0, {0xc000302fc0, 0x0, 0x80}, 0xc00027ae10)
        /home/runner/work/yq/yq/pkg/yqlib/data_tree_navigator.go:37 +0x1c3
github.com/mikefarah/yq/v4/pkg/yqlib.assignVariableOperator(0xc0000897d0, {0xc0001cbfb0, 0x0, 0x0}, 0xc00027ae40)
        /home/runner/work/yq/yq/pkg/yqlib/operator_variables.go:23 +0xbc
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x763d22, {0xc0001cbfb0, 0x0, 0x10}, 0xc00027ae40)
        /home/runner/work/yq/yq/pkg/yqlib/data_tree_navigator.go:37 +0x1c3
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0xc0000897d0, {0xc0001cbfb0, 0x0, 0x0}, 0xc00027b020)
        /home/runner/work/yq/yq/pkg/yqlib/operator_pipe.go:9 +0x3d
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0xc0002cf280, {0xc0001cbfb0, 0x0, 0xa0}, 0xc00027b020)
        /home/runner/work/yq/yq/pkg/yqlib/data_tree_navigator.go:37 +0x1c3
github.com/mikefarah/yq/v4/pkg/yqlib.(*allAtOnceEvaluator).EvaluateCandidateNodes(0xc0002dbcb8, {0x7fffd87da345, 0x7fffd87da3dc}, 0x8)
        /home/runner/work/yq/yq/pkg/yqlib/all_at_once_evaluator.go:41 +0x67
github.com/mikefarah/yq/v4/pkg/yqlib.(*allAtOnceEvaluator).EvaluateFiles(0xc00000e018, {0x7fffd87da345, 0x8f}, {0xc000089c90, 0x2, 0xc000014f5c}, {0x7ebe18, 0xc0002ccf00}, 0x1, {0x7eb3b0, ...})
        /home/runner/work/yq/yq/pkg/yqlib/all_at_once_evaluator.go:84 +0x35d
github.com/mikefarah/yq/v4/cmd.evaluateAll(0xc0000a5680, {0xc000089c80, 0x3, 0x3})
        /home/runner/work/yq/yq/cmd/evaluate_all_command.go:147 +0x156e
github.com/spf13/cobra.(*Command).execute(0xc0000a5680, {0xc000089c50, 0x3, 0x3})
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:856 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000a5180)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:974 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:902
main.main()
        /home/runner/work/yq/yq/yq.go:22 +0x190
$ yq --version
yq (https://github.com/mikefarah/yq/) version 4.19.1

Inputs:

1.yaml

abc:
 - a: 1
   c: 4
 - a: 2

2.yaml

abc:
 - a: 2
   b: 3
 - a: 2
mikefarah added a commit that referenced this issue Feb 9, 2022
@mikefarah
Copy link
Owner

The SIGV is definitely a bug, thanks for reporting. I've put a fix in for the next release.

That merge-by-array-key.sh was a temporary file I had accidentally checked in while working out a generic way to do just that. I've removed it from the rep (sorry for the confusion!)

Have a look at https://mikefarah.gitbook.io/yq/operators/multiply-merge#merge-arrays-of-objects-together-matching-on-a-key for the actual generic solution

@mikefarah
Copy link
Owner

SIGV fixed in 4.20.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants