MCPcopy Index your code
hub / github.com/klauspost/compress / fuzzFseEncoder

Function fuzzFseEncoder

zstd/blockenc.go:443–477  ·  view source on GitHub ↗

fuzzFseEncoder can be used to fuzz the FSE encoder.

(data []byte)

Source from the content-addressed store, hash-verified

441
442// fuzzFseEncoder can be used to fuzz the FSE encoder.
443func fuzzFseEncoder(data []byte) int {
444 if len(data) > maxSequences || len(data) < 2 {
445 return 0
446 }
447 enc := fseEncoder{}
448 hist := enc.Histogram()
449 maxSym := uint8(0)
450 for i, v := range data {
451 v = v & 63
452 data[i] = v
453 hist[v]++
454 if v > maxSym {
455 maxSym = v
456 }
457 }
458 if maxSym == 0 {
459 // All 0
460 return 0
461 }
462 cnt := int(slices.Max(hist[:maxSym]))
463 if cnt == len(data) {
464 // RLE
465 return 0
466 }
467 enc.HistogramFinished(maxSym, cnt)
468 err := enc.normalizeCount(len(data))
469 if err != nil {
470 return 0
471 }
472 _, err = enc.writeCount(nil)
473 if err != nil {
474 panic(err)
475 }
476 return 1
477}
478
479// encode will encode the block and append the output in b.output.
480// Previous offset codes must be pushed if more blocks are expected.

Callers

nothing calls this directly

Calls 4

HistogramMethod · 0.95
HistogramFinishedMethod · 0.95
normalizeCountMethod · 0.95
writeCountMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…