MSP-8520 up deps
This commit is contained in:
1 parent
c14f8441fb
commit
884aa6a439
304 files changed
+18223
-4352
No files matched your search
+3
-6
@@ -400,8 +400,9 @@ func (b *blockDec) decodeLiterals(in []byte, hist *history) (remain []byte, err
|
||||
}
|
||||
}
|
||||
var err error
|
||||
// Use our out buffer.
|
||||
huff.MaxDecodedSize = litRegenSize
|
||||
// Decoder.Decompress* uses cap(dst) for the size limit. Do not write
|
||||
// MaxDecodedSize on hist.huffTree: with a trained dictionary that
|
||||
// pointer aliases the shared dict.litEnc and concurrent DecodeAll races.
|
||||
if fourStreams {
|
||||
literals, err = huff.Decoder().Decompress4X(b.literalBuf[:0:litRegenSize], literals)
|
||||
} else {
|
||||
@@ -673,10 +674,6 @@ func (b *blockDec) executeSequences(hist *history) error {
|
||||
hbytes := hist.b
|
||||
if len(hbytes) > hist.windowSize {
|
||||
hbytes = hbytes[len(hbytes)-hist.windowSize:]
|
||||
// We do not need history anymore.
|
||||
if hist.dict != nil {
|
||||
hist.dict.content = nil
|
||||
}
|
||||
}
|
||||
hist.decoders.windowSize = hist.windowSize
|
||||
hist.decoders.out = b.dst[:0]
|
||||
|
||||
+64
-21
@@ -296,40 +296,81 @@ func BuildDict(o BuildDictOptions) ([]byte, error) {
|
||||
if offset > 3 {
|
||||
newOffsets[offset-3]++
|
||||
} else {
|
||||
newOffsets[uint32(o.Offsets[offset-1])]++
|
||||
// Repeat codes reference the training Offsets. Skip unset
|
||||
// (zero) entries so they are not ranked as real offsets.
|
||||
prev := o.Offsets[offset-1]
|
||||
if prev > 0 {
|
||||
newOffsets[uint32(prev)]++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Find most used offsets.
|
||||
var sortedOffsets []uint32
|
||||
for k := range newOffsets {
|
||||
if k == 0 {
|
||||
continue
|
||||
}
|
||||
sortedOffsets = append(sortedOffsets, k)
|
||||
}
|
||||
sort.Slice(sortedOffsets, func(i, j int) bool {
|
||||
a, b := sortedOffsets[i], sortedOffsets[j]
|
||||
if a == b {
|
||||
ca, cb := newOffsets[a], newOffsets[b]
|
||||
if ca == cb {
|
||||
// Prefer the longer offset
|
||||
return sortedOffsets[i] > sortedOffsets[j]
|
||||
return a > b
|
||||
}
|
||||
return newOffsets[sortedOffsets[i]] > newOffsets[sortedOffsets[j]]
|
||||
return ca > cb
|
||||
})
|
||||
if len(sortedOffsets) > 3 {
|
||||
if debug {
|
||||
print("Offsets:")
|
||||
for i, v := range sortedOffsets {
|
||||
if i > 20 {
|
||||
break
|
||||
}
|
||||
printf("[%d: %d],", v, newOffsets[v])
|
||||
if debug {
|
||||
print("Offsets:")
|
||||
for i, v := range sortedOffsets {
|
||||
if i > 20 {
|
||||
break
|
||||
}
|
||||
println("")
|
||||
printf("[%d: %d],", v, newOffsets[v])
|
||||
}
|
||||
|
||||
sortedOffsets = sortedOffsets[:3]
|
||||
println("")
|
||||
}
|
||||
for i, v := range sortedOffsets {
|
||||
o.Offsets[i] = int(v)
|
||||
// Dictionary recent-offsets must be three positive values within the
|
||||
// history. Ranked matches may be fewer (or empty when only unset
|
||||
// repeat codes were seen), so fill remaining slots with defaults.
|
||||
used := make(map[int]bool, 3)
|
||||
var finalOffsets [3]int
|
||||
nOff := 0
|
||||
for _, v := range sortedOffsets {
|
||||
iv := int(v)
|
||||
if iv <= 0 || iv > len(hist) || used[iv] {
|
||||
continue
|
||||
}
|
||||
finalOffsets[nOff] = iv
|
||||
used[iv] = true
|
||||
nOff++
|
||||
if nOff == 3 {
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, def := range []int{1, 4, 8} {
|
||||
if nOff == 3 {
|
||||
break
|
||||
}
|
||||
if def <= len(hist) && !used[def] {
|
||||
finalOffsets[nOff] = def
|
||||
used[def] = true
|
||||
nOff++
|
||||
}
|
||||
}
|
||||
for def := 1; nOff < 3 && def <= len(hist); def++ {
|
||||
if !used[def] {
|
||||
finalOffsets[nOff] = def
|
||||
used[def] = true
|
||||
nOff++
|
||||
}
|
||||
}
|
||||
if nOff < 3 {
|
||||
return nil, fmt.Errorf("could not determine 3 valid dictionary offsets (history size %d)", len(hist))
|
||||
}
|
||||
o.Offsets = finalOffsets
|
||||
if debug {
|
||||
println("New repeat offsets", o.Offsets)
|
||||
}
|
||||
@@ -337,6 +378,9 @@ func BuildDict(o BuildDictOptions) ([]byte, error) {
|
||||
if nUsed == 0 || seqs == 0 {
|
||||
return nil, fmt.Errorf("%d blocks, %d sequences found", nUsed, seqs)
|
||||
}
|
||||
if litTotal == 0 {
|
||||
return nil, errors.New("0 literals found")
|
||||
}
|
||||
if debug {
|
||||
println("Sequences:", seqs, "Blocks:", nUsed, "Literals:", litTotal)
|
||||
}
|
||||
@@ -517,11 +561,10 @@ func BuildDict(o BuildDictOptions) ([]byte, error) {
|
||||
out.Write(binary.LittleEndian.AppendUint32(nil, uint32(o.Offsets[1])))
|
||||
out.Write(binary.LittleEndian.AppendUint32(nil, uint32(o.Offsets[2])))
|
||||
out.Write(hist)
|
||||
if _, err := loadDict(out.Bytes()); err != nil {
|
||||
return nil, fmt.Errorf("built dictionary failed validation: %w", err)
|
||||
}
|
||||
if debug {
|
||||
_, err := loadDict(out.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
i, err := InspectDictionary(out.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
+2
-2
@@ -2081,7 +2081,7 @@ sequenceDecs_decodeSync_amd64_match_len_ofs_ok:
|
||||
MOVQ 16(SP), R13
|
||||
|
||||
// Check if we have enough space in s.out
|
||||
LEAQ (AX)(R13*1), R14
|
||||
LEAQ 16(AX)(R13*1), R14
|
||||
ADDQ R10, R14
|
||||
CMPQ R14, 32(SP)
|
||||
JA error_not_enough_space
|
||||
@@ -2601,7 +2601,7 @@ sequenceDecs_decodeSync_bmi2_match_len_ofs_ok:
|
||||
MOVQ 16(SP), R13
|
||||
|
||||
// Check if we have enough space in s.out
|
||||
LEAQ (CX)(R13*1), R14
|
||||
LEAQ 16(CX)(R13*1), R14
|
||||
ADDQ R9, R14
|
||||
CMPQ R14, 32(SP)
|
||||
JA error_not_enough_space
|
||||
|
||||
+323
-278
File diff suppressed because it is too large.
Load diff
+30
-3
@@ -77,6 +77,35 @@ const errorNotEnoughSpace = 5
|
||||
// error reported when bits are overread.
|
||||
const errorOverread = 6
|
||||
|
||||
// useSafeDecodeSync reports whether decodeSyncSimple must use the bounds-exact
|
||||
// ("safe") copy variants for the current buffer geometry.
|
||||
//
|
||||
// When the output and literal buffers have compressedBlockOverAlloc (16)
|
||||
// bytes of slack past their logical use, the assembly may use extended
|
||||
// memory copies that read and write in 16-byte blocks, overrunning the end
|
||||
// of a literal run or match by up to 15 bytes. Otherwise it must use the
|
||||
// bounds-exact ("safe") copies. This mirrors the analogous, always-dynamic
|
||||
// selection in executeSimple below.
|
||||
//
|
||||
// The unsafe copies were disabled in #644 (2022) as a mitigation for a
|
||||
// crash, but that crash's root cause — an unguarded bitReader overread that
|
||||
// produced out-of-range match offsets/lengths — was fixed three days later
|
||||
// in #645, which also added the fuzz corpus that has guarded this path since.
|
||||
// See #1168. An asan-instrumented fuzz job (see .github/workflows/go.yml)
|
||||
// covers the extended-copy path, which -race and plain fuzzing cannot.
|
||||
func (s *sequenceDecs) useSafeDecodeSync() bool {
|
||||
if s.maxSyncLen == 0 && cap(s.out)-len(s.out) < maxCompressedBlockSizeAlloc {
|
||||
return true
|
||||
}
|
||||
if s.maxSyncLen > 0 && cap(s.out)-len(s.out)-compressedBlockOverAlloc < int(s.maxSyncLen) {
|
||||
return true
|
||||
}
|
||||
if cap(s.literals) < len(s.literals)+compressedBlockOverAlloc {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// decode sequences from the stream with the provided history but without a dictionary.
|
||||
func (s *sequenceDecs) decodeSyncSimple(hist []byte) (bool, error) {
|
||||
if len(s.dict) > 0 {
|
||||
@@ -86,9 +115,7 @@ func (s *sequenceDecs) decodeSyncSimple(hist []byte) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// FIXME: Using unsafe memory copies leads to rare, random crashes
|
||||
// with fuzz testing. It is therefore disabled for now.
|
||||
const useSafe = true
|
||||
useSafe := s.useSafeDecodeSync()
|
||||
|
||||
br := s.br
|
||||
|
||||
|
||||
Reference in new issue
Block a user