File: fuzzer.c

package info (click to toggle)
pngquant 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: ansic: 1,472; sh: 532; makefile: 84
file content (34 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "rwpng.h"
#include "libimagequant.h"
#include "pngquant_opts.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  if (size < 2)
    return 0;

  char img[256];
  sprintf(img, "/tmp/libfuzzer.png");

  FILE *fp = fopen(img, "wb");
  if (!fp)
    return 0;
  fwrite(data, size, 1, fp);
  fclose(fp);

  liq_attr *attr = liq_attr_create();
  png24_image tmp = {.width=0};
  liq_image *input_image = NULL;
  read_image(attr, img, false, &tmp, &input_image, true, true, false);
  
  liq_attr_destroy(attr);
  if(input_image!=NULL){
    liq_image_destroy(input_image);
  }
  rwpng_free_image24(&tmp);
  unlink(img);
  return 0; 
}