github.com/fraugster/parquet-go@v0.12.0/types_fuzz.go (about)

     1  //go:build gofuzz
     2  // +build gofuzz
     3  
     4  package goparquet
     5  
     6  import (
     7  	"bytes"
     8  )
     9  
    10  func FuzzBooleanPlain(data []byte) int {
    11  	maxSize := len(data) * 8
    12  	d := booleanPlainDecoder{}
    13  	err := d.init(bytes.NewReader(data))
    14  	if err != nil {
    15  		return -1
    16  	}
    17  	dst1 := make([]interface{}, maxSize)
    18  	_, err = d.decodeValues(dst1)
    19  	if err != nil {
    20  		return 0
    21  	}
    22  
    23  	e := booleanPlainEncoder{}
    24  
    25  	if err := e.init(&bytes.Buffer{}); err != nil {
    26  		return -1
    27  	}
    28  
    29  	if err := e.encodeValues(dst1); err != nil {
    30  		return 0
    31  	}
    32  
    33  	if err := e.Close(); err != nil {
    34  		return 0
    35  	}
    36  
    37  	return 1
    38  }
    39  
    40  func FuzzBooleanRLE(data []byte) int {
    41  	maxSize := len(data) * 8
    42  	d := booleanRLEDecoder{}
    43  	err := d.init(bytes.NewReader(data))
    44  	if err != nil {
    45  		return -1
    46  	}
    47  	dst1 := make([]interface{}, maxSize)
    48  	_, err = d.decodeValues(dst1)
    49  	if err != nil {
    50  		return 0
    51  	}
    52  
    53  	e := booleanRLEEncoder{}
    54  
    55  	if err := e.init(&bytes.Buffer{}); err != nil {
    56  		return -1
    57  	}
    58  
    59  	if err := e.encodeValues(dst1); err != nil {
    60  		return 0
    61  	}
    62  
    63  	if err := e.Close(); err != nil {
    64  		return 0
    65  	}
    66  
    67  	return 1
    68  }
    69  
    70  func FuzzInt32DeltaBP(data []byte) int {
    71  	maxSize := len(data) / 4
    72  	d := int32DeltaBPDecoder{
    73  		deltaBitPackDecoder32: deltaBitPackDecoder32{
    74  			blockSize:      128,
    75  			miniBlockCount: 4,
    76  		},
    77  	}
    78  	err := d.init(bytes.NewReader(data))
    79  	if err != nil {
    80  		return -1
    81  	}
    82  	dst1 := make([]interface{}, maxSize)
    83  	_, err = d.decodeValues(dst1)
    84  	if err != nil {
    85  		return 0
    86  	}
    87  
    88  	e := int32DeltaBPEncoder{
    89  		deltaBitPackEncoder32: deltaBitPackEncoder32{
    90  			blockSize:      128,
    91  			miniBlockCount: 4,
    92  		},
    93  	}
    94  
    95  	if err := e.init(&bytes.Buffer{}); err != nil {
    96  		return -1
    97  	}
    98  
    99  	if err := e.encodeValues(dst1); err != nil {
   100  		return 0
   101  	}
   102  
   103  	if err := e.Close(); err != nil {
   104  		return 0
   105  	}
   106  
   107  	return 1
   108  }
   109  
   110  func FuzzInt32Plain(data []byte) int {
   111  	maxSize := len(data) / 4
   112  	d := int32PlainDecoder{}
   113  	err := d.init(bytes.NewReader(data))
   114  	if err != nil {
   115  		panic("unexpected error in init")
   116  	}
   117  	dst1 := make([]interface{}, maxSize)
   118  	_, err = d.decodeValues(dst1)
   119  	if err != nil {
   120  		return 0
   121  	}
   122  
   123  	e := int32PlainEncoder{}
   124  
   125  	if err := e.init(&bytes.Buffer{}); err != nil {
   126  		panic("unexpected error in init")
   127  	}
   128  
   129  	if err := e.encodeValues(dst1); err != nil {
   130  		return 0
   131  	}
   132  
   133  	if err := e.Close(); err != nil {
   134  		return 0
   135  	}
   136  
   137  	return 1
   138  }
   139  
   140  func FuzzFloatPlain(data []byte) int {
   141  	maxSize := len(data) / 4
   142  	d := floatPlainDecoder{}
   143  	err := d.init(bytes.NewReader(data))
   144  	if err != nil {
   145  		panic("unexpected error in init")
   146  	}
   147  	dst1 := make([]interface{}, maxSize)
   148  	_, err = d.decodeValues(dst1)
   149  	if err != nil {
   150  		return -1
   151  	}
   152  
   153  	e := floatPlainEncoder{}
   154  
   155  	if err := e.init(&bytes.Buffer{}); err != nil {
   156  		panic("unexpected error in init")
   157  	}
   158  
   159  	if err := e.encodeValues(dst1); err != nil {
   160  		return -1
   161  	}
   162  
   163  	if err := e.Close(); err != nil {
   164  		return -1
   165  	}
   166  
   167  	return 1
   168  }
   169  
   170  func FuzzDoublePlain(data []byte) int {
   171  	maxSize := len(data) / 8
   172  	d := doublePlainDecoder{}
   173  	err := d.init(bytes.NewReader(data))
   174  	if err != nil {
   175  		panic("unexpected error in init")
   176  	}
   177  	dst1 := make([]interface{}, maxSize)
   178  	_, err = d.decodeValues(dst1)
   179  	if err != nil {
   180  		return -1
   181  	}
   182  
   183  	e := doublePlainEncoder{}
   184  
   185  	if err := e.init(&bytes.Buffer{}); err != nil {
   186  		panic("unexpected error in init")
   187  	}
   188  
   189  	if err := e.encodeValues(dst1); err != nil {
   190  		return -1
   191  	}
   192  
   193  	if err := e.Close(); err != nil {
   194  		return -1
   195  	}
   196  
   197  	return 1
   198  }