mirror of
https://github.com/wader/fq.git
synced 2024-12-23 13:22:58 +03:00
fuzz: Fuzz all formats
Fix string readers to not panic on make slice with bogus sizes
This commit is contained in:
parent
6fcfa77300
commit
b8efd8e549
@ -51,7 +51,11 @@ func (ft *fuzzTest) Stderr() interp.Output { return fuzzTestOutput{os.Std
|
|||||||
func (ft *fuzzTest) InterruptChan() chan struct{} { return nil }
|
func (ft *fuzzTest) InterruptChan() chan struct{} { return nil }
|
||||||
func (ft *fuzzTest) Environ() []string { return nil }
|
func (ft *fuzzTest) Environ() []string { return nil }
|
||||||
func (ft *fuzzTest) Args() []string {
|
func (ft *fuzzTest) Args() []string {
|
||||||
return []string{}
|
return []string{
|
||||||
|
`fq`,
|
||||||
|
`-d`, `raw`,
|
||||||
|
`(_registry.groups | keys[] | select(. != "all")) as $f | decode($f)?`,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
func (ft *fuzzTest) ConfigDir() (string, error) { return "/config", nil }
|
func (ft *fuzzTest) ConfigDir() (string, error) { return "/config", nil }
|
||||||
func (ft *fuzzTest) FS() fs.FS { return fuzzFS{} }
|
func (ft *fuzzTest) FS() fs.FS { return fuzzFS{} }
|
||||||
|
@ -127,6 +127,14 @@ var UTF16BE = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)
|
|||||||
var UTF16LE = unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
|
var UTF16LE = unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
|
||||||
|
|
||||||
func (d *D) tryText(nBytes int, e encoding.Encoding) (string, error) {
|
func (d *D) tryText(nBytes int, e encoding.Encoding) (string, error) {
|
||||||
|
if nBytes < 0 {
|
||||||
|
return "", fmt.Errorf("tryText nBytes must be >= 0 (%d)", nBytes)
|
||||||
|
}
|
||||||
|
bytesLeft := d.BitsLeft() / 8
|
||||||
|
if int64(nBytes) > bytesLeft {
|
||||||
|
return "", fmt.Errorf("tryText nBytes %d outside buffer, %d bytes left", nBytes, bytesLeft)
|
||||||
|
}
|
||||||
|
|
||||||
bs, err := d.bitBuf.BytesLen(nBytes)
|
bs, err := d.bitBuf.BytesLen(nBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -139,6 +147,17 @@ func (d *D) tryText(nBytes int, e encoding.Encoding) (string, error) {
|
|||||||
// fixedBytes if != -1 read nBytes but trim to length
|
// fixedBytes if != -1 read nBytes but trim to length
|
||||||
//nolint:unparam
|
//nolint:unparam
|
||||||
func (d *D) tryTextLenPrefixed(lenBits int, fixedBytes int, e encoding.Encoding) (string, error) {
|
func (d *D) tryTextLenPrefixed(lenBits int, fixedBytes int, e encoding.Encoding) (string, error) {
|
||||||
|
if lenBits < 0 {
|
||||||
|
return "", fmt.Errorf("tryTextLenPrefixed lenBits must be >= 0 (%d)", lenBits)
|
||||||
|
}
|
||||||
|
if fixedBytes < 0 {
|
||||||
|
return "", fmt.Errorf("tryTextLenPrefixed fixedBytes must be >= 0 (%d)", fixedBytes)
|
||||||
|
}
|
||||||
|
bytesLeft := d.BitsLeft() / 8
|
||||||
|
if int64(fixedBytes) > bytesLeft {
|
||||||
|
return "", fmt.Errorf("tryTextLenPrefixed fixedBytes %d outside, %d bytes left", fixedBytes, bytesLeft)
|
||||||
|
}
|
||||||
|
|
||||||
p := d.Pos()
|
p := d.Pos()
|
||||||
l, err := d.bits(lenBits)
|
l, err := d.bits(lenBits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -163,6 +182,10 @@ func (d *D) tryTextLenPrefixed(lenBits int, fixedBytes int, e encoding.Encoding)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *D) tryTextNull(nullBytes int, e encoding.Encoding) (string, error) {
|
func (d *D) tryTextNull(nullBytes int, e encoding.Encoding) (string, error) {
|
||||||
|
if nullBytes < 1 {
|
||||||
|
return "", fmt.Errorf("tryTextNull nullBytes must be >= 1 (%d)", nullBytes)
|
||||||
|
}
|
||||||
|
|
||||||
p := d.Pos()
|
p := d.Pos()
|
||||||
peekBits, _, err := d.TryPeekFind(nullBytes*8, 8, -1, func(v uint64) bool { return v == 0 })
|
peekBits, _, err := d.TryPeekFind(nullBytes*8, 8, -1, func(v uint64) bool { return v == 0 })
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -179,6 +202,14 @@ func (d *D) tryTextNull(nullBytes int, e encoding.Encoding) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *D) tryTextNullLen(fixedBytes int, e encoding.Encoding) (string, error) {
|
func (d *D) tryTextNullLen(fixedBytes int, e encoding.Encoding) (string, error) {
|
||||||
|
if fixedBytes < 0 {
|
||||||
|
return "", fmt.Errorf("tryTextNullLen fixedBytes must be >= 0 (%d)", fixedBytes)
|
||||||
|
}
|
||||||
|
bytesLeft := d.BitsLeft() / 8
|
||||||
|
if int64(fixedBytes) > bytesLeft {
|
||||||
|
return "", fmt.Errorf("tryTextNullLen fixedBytes %d outside, %d bytes left", fixedBytes, bytesLeft)
|
||||||
|
}
|
||||||
|
|
||||||
bs, err := d.bitBuf.BytesLen(fixedBytes)
|
bs, err := d.bitBuf.BytesLen(fixedBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
Loading…
Reference in New Issue
Block a user