qri-io / qri

you're invited to a data party!
https://qri.io
GNU General Public License v3.0
1.1k stars 66 forks source link

Segmentation violation for qri diff structure.json #1249

Closed hbruch closed 4 years ago

hbruch commented 4 years ago

Expected behavior

qri diff structure.json executed in the working dir of a dataset should return the diff compared to last saved version.

Actual behavior

A segmentation violation occurs:

$ qri diff structure.json
for linked dataset [mfdz/nvbw_haltestellen]

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x50c3d01]

goroutine 1 [running]:
github.com/qri-io/qri/lib.(*DatasetRequests).Diff(0xc000410000, 0xc0003e02a0, 0xc0002c9bc0, 0x0, 0xc000650120)
    /Users/hbruch/git/go-code/qri/lib/diff.go:229 +0xb11
github.com/qri-io/qri/cmd.(*DiffOptions).Run(0xc0002ce000, 0x5a2fb60, 0xc00031a370)
    /Users/hbruch/git/go-code/qri/cmd/diff.go:130 +0x12a
github.com/qri-io/qri/cmd.NewDiffCommand.func1(0xc0003bec80, 0xc000121170, 0x1, 0x1, 0x0, 0x0)
    /Users/hbruch/git/go-code/qri/cmd/diff.go:56 +0x97
github.com/spf13/cobra.(*Command).execute(0xc0003bec80, 0xc000121130, 0x1, 0x1, 0xc0003bec80, 0xc000121130)
    /Users/hbruch/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:826 +0x453
github.com/spf13/cobra.(*Command).ExecuteC(0xc00034c000, 0xc000138390, 0x57a3bb0, 0x5a024c0)
    /Users/hbruch/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
    /Users/hbruch/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
github.com/qri-io/qri/cmd.Execute()
    /Users/hbruch/git/go-code/qri/cmd/cmd.go:53 +0x153
main.main()
    /Users/hbruch/git/go-code/qri/main.go:16 +0x20

Additional info

qri: HEAD (c21419b3a0df46e) OS: MacOS Mojave 10.14.6 (18G103)

dustmop commented 4 years ago

We recently saw a segfault in the deepdiff library that happened when a user had a zero-byte body file. Do you happen to still have the body file that was in use when this crash was encountered? I wonder if it's the same issue.

dustmop commented 4 years ago

Nevermind, this is unrelated to having an empty file, should have been able to tell from the stacktrace. This happens because the "structure.json" string is treated as a component selector, and there's no component with that name. We're not checking for this problem, so resolving the component leads to a segfault.

If might make sense to also allow for filenames instead of just components, and if the provided string is neither a filename nor component, print an error.