Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
update_fuzzer.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright 2021 Google LLC
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8# This tool updates the OSS-Fuzz corpus using Google Cloud's 'gsutil' tool.
9
10# You will need to be given access to the Google Storage fuzzer repo (at
11# gs://skia-fuzzer/oss-fuzz/) by the Skia Infra team.
12
13# You will also need to set up credentials for gsutil on your machine by running:
14# gcloud auth login
15
16import os
17import subprocess
18import tempfile
19import zipfile
20
21# Locate this script in the file system.
22startDir = os.path.dirname(os.path.abspath(__file__))
23fileNum = 1
24
25# Prepare two scratch zip files, one for the input data as-is and another with 256-byte padding.
26with tempfile.NamedTemporaryFile(suffix='primary.zip', delete=False, mode='w') as pathToZip:
27 with zipfile.ZipFile(pathToZip.name, 'w', zipfile.ZIP_DEFLATED) as archive:
28 # Iterate over every file in this directory and use it to assemble our corpus.
29 for root, dirs, files in os.walk(startDir):
30 for file in files:
31 # Exclude files that won't be useful fuzzer inputs.
32 if (not file.startswith('.') # Hidden
33 and not file.endswith('.py') # Python
34 and not file.endswith('.test') # ES2 conformance script
35 and not file.endswith('.txt')): # Text
36 # Prepend a number to each output filename to guarantee uniqueness.
37 pathInZip = '%d_%s' % (fileNum, file)
38 fileNum += 1
39 with open('%s/%s' % (root, file), 'rb') as skslFile:
40 # Read the SkSL text as input.
41 inputSkSL = skslFile.read()
42 # Copy the SkSL into our zip archive.
43 archive.writestr(pathInZip, inputSkSL)
44
45 try:
46 # Upload our zip file to cloud storage.
47 output = subprocess.check_output(
48 ['gsutil', 'cp', pathToZip.name,
49 'gs://skia-fuzzer/oss-fuzz/sksl_seed_corpus.zip'],
50 stderr=subprocess.STDOUT)
51
52 # Make the uploaded file world-readable.
53 output = subprocess.check_output(
54 ['gsutil', 'acl', 'ch', '-u', 'AllUsers:R',
55 'gs://skia-fuzzer/oss-fuzz/sksl_seed_corpus.zip'],
56 stderr=subprocess.STDOUT)
57
58 except subprocess.CalledProcessError as err:
59 # Report the error.
60 print("### Unable to upload fuzzer corpus to Google Cloud:")
61 print(" " + "\n ".join(err.output.splitlines()))
62 print("\nPlease read the notes at the top of update_fuzzer.py for next steps.\n")
63 sys.exit(err.returncode)
void print(void *str)
Definition bridge.cpp:126