| 1 | package rardecode |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "io" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // A crafted RAR 5.0 archive whose compressed stream encodes an LZ |
| 10 | // back-reference offset larger than the decode window. Before the fix |
| 11 | // this made the source index in copyBytes negative and panicked with a |
| 12 | // slice bounds out of range. Decoding malformed input must return an |
| 13 | // error, not panic. |
| 14 | func TestCopyBytesNegativeOffsetNoPanic(t *testing.T) { |
| 15 | archive := []byte{82, 97, 114, 33, 26, 7, 1, 0, 243, 225, 130, 235, 11, 1, 5, 7, 0, 6, 1, 1, 128, 128, 128, 0, 102, 220, 119, 193, 35, 2, 3, 11, 158, 0, 4, 164, 0, 180, 131, 2, 105, 46, 107, 110, 128, 5, 1, 5, 97, 46, 116, 120, 116, 10, 3, 19, 24, 30, 132, 106, 141, 65, 52, 36, 198, 135, 27, 52, 67, 47, 179, 45, 196, 85, 92, 97, 32, 121, 37, 48, 48, 127, 33, 170, 243, 95, 1, 33, 88, 42, 42, 48, 48, 65} |
| 16 | r, err := NewReader(bytes.NewReader(archive)) |
| 17 | if err != nil { |
| 18 | return |
| 19 | } |
| 20 | for { |
| 21 | if _, err := r.Next(); err != nil { |
| 22 | break |
| 23 | } |
| 24 | if _, err := io.Copy(io.Discard, r); err != nil { |
| 25 | break |
| 26 | } |
| 27 | } |
| 28 | } |