mirror of https://github.com/restic/restic.git
Fix special case with null byte input
This commit is contained in:
parent
b3a4bbc850
commit
83ea81d8c3
|
@ -154,7 +154,8 @@ func (c *chunker) Next() (*Chunk, error) {
|
||||||
if err == io.EOF && !c.closed {
|
if err == io.EOF && !c.closed {
|
||||||
c.closed = true
|
c.closed = true
|
||||||
|
|
||||||
// return current chunk
|
// return current chunk, if any bytes have been processed
|
||||||
|
if c.count > 0 {
|
||||||
return &Chunk{
|
return &Chunk{
|
||||||
Start: c.start,
|
Start: c.start,
|
||||||
Length: c.count,
|
Length: c.count,
|
||||||
|
@ -162,6 +163,7 @@ func (c *chunker) Next() (*Chunk, error) {
|
||||||
Data: c.data,
|
Data: c.data,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -46,6 +46,14 @@ var chunks1 = []chunk{
|
||||||
chunk{237392, 0x00184c5825e18636},
|
chunk{237392, 0x00184c5825e18636},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test if nullbytes are correctly split, even if length is a multiple of MinSize.
|
||||||
|
var chunks2 = []chunk{
|
||||||
|
chunk{chunker.MinSize, 0},
|
||||||
|
chunk{chunker.MinSize, 0},
|
||||||
|
chunk{chunker.MinSize, 0},
|
||||||
|
chunk{chunker.MinSize, 0},
|
||||||
|
}
|
||||||
|
|
||||||
func test_with_data(t *testing.T, chunker chunker.Chunker, chunks []chunk) {
|
func test_with_data(t *testing.T, chunker chunker.Chunker, chunks []chunk) {
|
||||||
for i, chunk := range chunks {
|
for i, chunk := range chunks {
|
||||||
c, err := chunker.Next()
|
c, err := chunker.Next()
|
||||||
|
@ -105,10 +113,14 @@ func get_random(seed, count int) []byte {
|
||||||
func TestChunker(t *testing.T) {
|
func TestChunker(t *testing.T) {
|
||||||
// setup data source
|
// setup data source
|
||||||
buf := get_random(23, 32*1024*1024)
|
buf := get_random(23, 32*1024*1024)
|
||||||
|
|
||||||
ch := chunker.New(bytes.NewReader(buf))
|
ch := chunker.New(bytes.NewReader(buf))
|
||||||
|
|
||||||
test_with_data(t, ch, chunks1)
|
test_with_data(t, ch, chunks1)
|
||||||
|
|
||||||
|
// setup nullbyte data source
|
||||||
|
buf = bytes.Repeat([]byte{0}, len(chunks2)*chunker.MinSize)
|
||||||
|
ch = chunker.New(bytes.NewReader(buf))
|
||||||
|
|
||||||
|
test_with_data(t, ch, chunks2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkChunker(b *testing.B) {
|
func BenchmarkChunker(b *testing.B) {
|
||||||
|
|
Loading…
Reference in New Issue