Commit 7f66e072 authored by Abhishek Arya's avatar Abhishek Arya Committed by Commit Bot

Restrict maximum size for seed corpus in fuzzer archives.

R=mmoroz@chromium.org,metzman@chromium.org
TBR=maxmorin@chromium.org

Change-Id: I3929bc2a22537cc0f83aec69693e99b8ae10223a
Bug: 952036
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1565241
Commit-Queue: Abhishek Arya <inferno@chromium.org>
Reviewed-by: default avatarMax Moroz <mmoroz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650389}
parent fe2f03c0
......@@ -16,6 +16,8 @@ import sys
import warnings
import zipfile
SEED_CORPUS_LIMIT_MB = 100
def main():
parser = argparse.ArgumentParser(description="Generate fuzzer config.")
......@@ -26,6 +28,7 @@ def main():
args = parser.parse_args()
corpus_files = []
seed_corpus_path = args.output
for directory in args.corpus_directories:
if not os.path.exists(directory):
......@@ -36,7 +39,7 @@ def main():
full_filename = os.path.join(dirpath, filename)
corpus_files.append(full_filename)
with zipfile.ZipFile(args.output, 'w') as z:
with zipfile.ZipFile(seed_corpus_path, 'w') as z:
# Turn warnings into errors to interrupt the build: crbug.com/653920.
with warnings.catch_warnings():
warnings.simplefilter("error")
......@@ -45,6 +48,10 @@ def main():
arcname = '%016d' % i
z.write(corpus_file, arcname)
if os.path.getsize(seed_corpus_path) > SEED_CORPUS_LIMIT_MB * 1024 * 1024:
print('Seed corpus %s exceeds maximum allowed size (%d MB).' %
(seed_corpus_path, SEED_CORPUS_LIMIT_MB))
sys.exit(-1)
if __name__ == '__main__':
main()
......@@ -9,6 +9,7 @@ from __future__ import print_function
from array import array
import os
import random
import shutil
import sys
MAX_INPUT_SIZE = 5000 # < 1 MB so we don't blow up fuzzer build sizes.
......@@ -42,9 +43,10 @@ def main():
sys.exit(1)
output_path = sys.argv[1]
# Create output directory if missing.
if not os.path.exists(output_path):
os.makedirs(output_path)
# Start with a clean output directory.
if os.path.exists(output_path):
shutil.rmtree(output_path)
os.makedirs(output_path)
# List of valid input sizes.
N = [n for n in range(MAX_INPUT_SIZE) if IsValidSize(n)]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment