Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions decode_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func (d *decodeReader) copyBytes(length, offset int) {
d.win[d.w] = d.win[i]
d.w++
i++
if i >= d.size {
i = 0
}
length--
}
}
Expand Down
15 changes: 15 additions & 0 deletions decode_reader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package rardecode

import "testing"

func TestCopyBytes_SourceIndexWraps(t *testing.T) {
d := &decodeReader{size: 8, win: make([]byte, 8)}
d.win[6] = 0xAA
d.win[7] = 0xBB
d.w = 4
// offset=6: source starts at (4-6)%8 = 6, wraps past 7 to 0
d.copyBytes(4, 6)
if d.win[4] != 0xAA || d.win[5] != 0xBB {
t.Errorf("first two bytes wrong: got %x %x, want AA BB", d.win[4], d.win[5])
}
}