Harden scan robustness and tests

This commit is contained in:
ZacharyZcR
2026-06-14 22:23:48 +08:00
parent 5ad914a1bb
commit c49c23c7f0
100 changed files with 4483 additions and 412 deletions
+39
View File
@@ -0,0 +1,39 @@
//go:build (plugin_rsync || !plugin_selective) && go1.21
package services
import (
"io"
"testing"
)
type chunkedRsyncReader struct {
data []byte
chunkSize int
}
func (r *chunkedRsyncReader) Read(p []byte) (int, error) {
if len(r.data) == 0 {
return 0, io.EOF
}
n := len(r.data)
if r.chunkSize > 0 && n > r.chunkSize {
n = r.chunkSize
}
if n > len(p) {
n = len(p)
}
copy(p, r.data[:n])
r.data = r.data[n:]
return n, nil
}
func TestReadRsyncLineHandlesChunkedReads(t *testing.T) {
got, err := readRsyncLine(&chunkedRsyncReader{data: []byte("@RSYNCD: 31.0\nrest"), chunkSize: 1}, 256)
if err != nil {
t.Fatalf("readRsyncLine() error = %v", err)
}
if got != "@RSYNCD: 31.0\n" {
t.Fatalf("readRsyncLine() = %q", got)
}
}