frame_test.go 737 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package gocql
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. func TestFuzzBugs(t *testing.T) {
  7. // these inputs are found using go-fuzz (https://github.com/dvyukov/go-fuzz)
  8. // and should cause a panic unless fixed.
  9. tests := []struct {
  10. input []byte
  11. }{
  12. {input: []byte("00000\xa0000")},
  13. }
  14. for i, test := range tests {
  15. t.Logf("test %d input: %q", i, test.input)
  16. var bw bytes.Buffer
  17. r := bytes.NewReader(test.input)
  18. head, err := readHeader(r, make([]byte, 9))
  19. if err != nil {
  20. continue
  21. }
  22. framer := newFramer(r, &bw, nil, 3)
  23. err = framer.readFrame(&head)
  24. if err != nil {
  25. continue
  26. }
  27. _, err = framer.parseFrame()
  28. if err != nil {
  29. continue
  30. }
  31. t.Errorf("(%d) expected to fail for input %q", i, test.input)
  32. }
  33. }