mirror of
				https://github.com/aler9/rtsp-simple-server
				synced 2025-10-31 11:06:28 +08:00 
			
		
		
		
	improve fuzz tests (#3596)
This commit is contained in:
		| @@ -322,6 +322,9 @@ func FuzzUnmarshal(f *testing.F) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	f.Fuzz(func(_ *testing.T, b []byte) { | 	f.Fuzz(func(_ *testing.T, b []byte) { | ||||||
| 		Unmarshal(b) //nolint:errcheck | 		what, err := Unmarshal(b) | ||||||
|  | 		if err == nil { | ||||||
|  | 			Marshal(what) //nolint:errcheck | ||||||
|  | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -160,27 +160,39 @@ func TestChunkMarshal(t *testing.T) { | |||||||
| func FuzzChunk0Read(f *testing.F) { | func FuzzChunk0Read(f *testing.F) { | ||||||
| 	f.Fuzz(func(_ *testing.T, b []byte) { | 	f.Fuzz(func(_ *testing.T, b []byte) { | ||||||
| 		var chunk Chunk0 | 		var chunk Chunk0 | ||||||
| 		chunk.Read(bytes.NewReader(b), 65536, false) //nolint:errcheck | 		err := chunk.Read(bytes.NewReader(b), 65536, false) | ||||||
|  | 		if err == nil { | ||||||
|  | 			chunk.Marshal(false) //nolint:errcheck | ||||||
|  | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| func FuzzChunk1Read(f *testing.F) { | func FuzzChunk1Read(f *testing.F) { | ||||||
| 	f.Fuzz(func(_ *testing.T, b []byte) { | 	f.Fuzz(func(_ *testing.T, b []byte) { | ||||||
| 		var chunk Chunk1 | 		var chunk Chunk1 | ||||||
| 		chunk.Read(bytes.NewReader(b), 65536, false) //nolint:errcheck | 		err := chunk.Read(bytes.NewReader(b), 65536, false) | ||||||
|  | 		if err == nil { | ||||||
|  | 			chunk.Marshal(false) //nolint:errcheck | ||||||
|  | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| func FuzzChunk2Read(f *testing.F) { | func FuzzChunk2Read(f *testing.F) { | ||||||
| 	f.Fuzz(func(_ *testing.T, b []byte) { | 	f.Fuzz(func(_ *testing.T, b []byte) { | ||||||
| 		var chunk Chunk2 | 		var chunk Chunk2 | ||||||
| 		chunk.Read(bytes.NewReader(b), 65536, false) //nolint:errcheck | 		err := chunk.Read(bytes.NewReader(b), 65536, false) | ||||||
|  | 		if err == nil { | ||||||
|  | 			chunk.Marshal(false) //nolint:errcheck | ||||||
|  | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| func FuzzChunk3Read(f *testing.F) { | func FuzzChunk3Read(f *testing.F) { | ||||||
| 	f.Fuzz(func(_ *testing.T, b []byte) { | 	f.Fuzz(func(_ *testing.T, b []byte) { | ||||||
| 		var chunk Chunk3 | 		var chunk Chunk3 | ||||||
| 		chunk.Read(bytes.NewReader(b), 65536, true) //nolint:errcheck | 		err := chunk.Read(bytes.NewReader(b), 65536, true) | ||||||
|  | 		if err == nil { | ||||||
|  | 			chunk.Marshal(false) //nolint:errcheck | ||||||
|  | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -38,6 +38,7 @@ func TestHandshake(t *testing.T) { | |||||||
|  |  | ||||||
| 			clientInKey, clientOutKey, err := DoClient(rw, ca == "encrypted", true) | 			clientInKey, clientOutKey, err := DoClient(rw, ca == "encrypted", true) | ||||||
| 			require.NoError(t, err) | 			require.NoError(t, err) | ||||||
|  |  | ||||||
| 			<-done | 			<-done | ||||||
|  |  | ||||||
| 			if ca == "encrypted" { | 			if ca == "encrypted" { | ||||||
|   | |||||||
| @@ -297,9 +297,18 @@ func FuzzReader(f *testing.F) { | |||||||
| 		0x01, 0x00, 0x00, 0x00, 0x88, 0x68, 0x76, 0x63, | 		0x01, 0x00, 0x00, 0x00, 0x88, 0x68, 0x76, 0x63, | ||||||
| 		0x31, 0x01, 0x02, 0x03, | 		0x31, 0x01, 0x02, 0x03, | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| 	f.Fuzz(func(_ *testing.T, b []byte) { | 	f.Fuzz(func(_ *testing.T, b []byte) { | ||||||
| 		bc := bytecounter.NewReader(bytes.NewReader(b)) | 		bcr := bytecounter.NewReader(bytes.NewReader(b)) | ||||||
| 		r := NewReader(bc, bc, nil) | 		r := NewReader(bcr, bcr, nil) | ||||||
| 		r.Read() //nolint:errcheck |  | ||||||
|  | 		var buf bytes.Buffer | ||||||
|  | 		bcw := bytecounter.NewWriter(&buf) | ||||||
|  | 		w := NewWriter(bcw, bcw, true) | ||||||
|  |  | ||||||
|  | 		msg, err := r.Read() | ||||||
|  | 		if err == nil { | ||||||
|  | 			w.Write(msg) //nolint:errcheck | ||||||
|  | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -270,14 +270,20 @@ func TestReaderAcknowledge(t *testing.T) { | |||||||
|  |  | ||||||
| func FuzzReader(f *testing.F) { | func FuzzReader(f *testing.F) { | ||||||
| 	f.Fuzz(func(_ *testing.T, b []byte) { | 	f.Fuzz(func(_ *testing.T, b []byte) { | ||||||
| 		br := bytecounter.NewReader(bytes.NewReader(b)) | 		bcr := bytecounter.NewReader(bytes.NewReader(b)) | ||||||
| 		r := NewReader(br, br, func(_ uint32) error { | 		r := NewReader(bcr, bcr, func(_ uint32) error { | ||||||
| 			return nil | 			return nil | ||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
|  | 		var buf bytes.Buffer | ||||||
|  | 		bcw := bytecounter.NewWriter(&buf) | ||||||
|  | 		w := NewWriter(bcw, bcw, true) | ||||||
|  |  | ||||||
| 		for { | 		for { | ||||||
| 			_, err := r.Read() | 			msg, err := r.Read() | ||||||
| 			if err != nil { | 			if err == nil { | ||||||
|  | 				w.Write(msg) //nolint:errcheck | ||||||
|  | 			} else { | ||||||
| 				break | 				break | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Alessandro Ros
					Alessandro Ros