mirror of
https://github.com/golang/go
synced 2024-11-18 15:44:41 -07:00
internal/zstd: fix copyFromWindow when match extends past window
For #62513
This commit is contained in:
parent
4a310877f2
commit
4dd16fcfa8
@ -388,46 +388,38 @@ func (r *Reader) copyFromWindow(rbr *reverseBitReader, offset, match uint32) err
|
|||||||
return rbr.makeError("invalid zero offset")
|
return rbr.makeError("invalid zero offset")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Offset may point into the buffer or the window and
|
||||||
|
// match may extend past the end of the initial buffer.
|
||||||
|
// |--r.window--|--r.buffer--|
|
||||||
|
// |<-----offset------|
|
||||||
|
// |------match----------->|
|
||||||
|
bufferOffset := uint32(0)
|
||||||
lenBlock := uint32(len(r.buffer))
|
lenBlock := uint32(len(r.buffer))
|
||||||
if lenBlock < offset {
|
if lenBlock < offset {
|
||||||
lenWindow := r.window.len()
|
lenWindow := r.window.len()
|
||||||
windowOffset := offset - lenBlock
|
copy := offset - lenBlock
|
||||||
if windowOffset > lenWindow {
|
if copy > lenWindow {
|
||||||
return rbr.makeError("offset past window")
|
return rbr.makeError("offset past window")
|
||||||
}
|
}
|
||||||
from := lenWindow - windowOffset
|
windowOffset := lenWindow - copy
|
||||||
if from+match <= lenWindow {
|
if copy > match {
|
||||||
r.buffer = r.window.appendTo(r.buffer, from, from+match)
|
copy = match
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
r.buffer = r.window.appendTo(r.buffer, from, lenWindow)
|
r.buffer = r.window.appendTo(r.buffer, windowOffset, windowOffset+copy)
|
||||||
copied := lenWindow - from
|
match -= copy
|
||||||
offset -= copied
|
} else {
|
||||||
match -= copied
|
bufferOffset = lenBlock - offset
|
||||||
|
|
||||||
if offset == 0 && match > 0 {
|
|
||||||
return rbr.makeError("invalid offset")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
from := lenBlock - offset
|
|
||||||
if offset >= match {
|
|
||||||
r.buffer = append(r.buffer, r.buffer[from:from+match]...)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are being asked to copy data that we are adding to the
|
// We are being asked to copy data that we are adding to the
|
||||||
// buffer in the same copy.
|
// buffer in the same copy.
|
||||||
for match > 0 {
|
for match > 0 {
|
||||||
var copy uint32
|
copy := uint32(len(r.buffer)) - bufferOffset
|
||||||
if offset >= match {
|
if copy > match {
|
||||||
copy = match
|
copy = match
|
||||||
} else {
|
|
||||||
copy = offset
|
|
||||||
}
|
}
|
||||||
r.buffer = append(r.buffer, r.buffer[from:from+copy]...)
|
r.buffer = append(r.buffer, r.buffer[bufferOffset:bufferOffset+copy]...)
|
||||||
match -= copy
|
match -= copy
|
||||||
from += copy
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
BIN
src/internal/zstd/testdata/f2a8e35c.helloworld-11000x.zst
vendored
Normal file
BIN
src/internal/zstd/testdata/f2a8e35c.helloworld-11000x.zst
vendored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user