-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
mcap cat
SIGSEGV when no schema present (#998)
### Public-Facing Changes `mcap cat` used to crash on some valid, but uncommon files. This fixes the crash. ### Description Mcap spec [allows for a missing schema](https://mcap.dev/spec#channel-op0x04). Currently, `mcap cat` crashes with a nil pointer dereference on such a file (unless you pass `--json`). After this change, `mcap cat` will print `[no schema]` instead of a schema for schemaless channels. Also added another test to `cat_test.go`, and added tests for `mcap info` in `info_test.go`
- Loading branch information
Showing
4 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/foxglove/mcap/go/mcap" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInfo(t *testing.T) { | ||
err := filepath.Walk("../../../../tests/conformance/data/", func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() { | ||
return nil | ||
} | ||
if strings.HasSuffix(path, ".mcap") { | ||
t.Run(path, func(t *testing.T) { | ||
input, err := os.ReadFile(path) | ||
assert.Nil(t, err) | ||
r := bytes.NewReader(input) | ||
w := new(bytes.Buffer) | ||
|
||
reader, err := mcap.NewReader(r) | ||
assert.Nil(t, err) | ||
defer reader.Close() | ||
info, err := reader.Info() | ||
assert.Nil(t, err) | ||
err = printInfo(w, info) | ||
assert.Nil(t, err) | ||
}) | ||
} | ||
return nil | ||
}) | ||
assert.Nil(t, err) | ||
} |