Coverage for /pythoncovmergedfiles/medio/medio/src/fuzz_fix.py: 50%
36 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:33 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:33 +0000
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12#!/usr/bin/python3
13# Copyright 2022 Google LLC
14#
15# Licensed under the Apache License, Version 2.0 (the "License");
16# you may not use this file except in compliance with the License.
17# You may obtain a copy of the License at
18#
19# http://www.apache.org/licenses/LICENSE-2.0
20#
21# Unless required by applicable law or agreed to in writing, software
22# distributed under the License is distributed on an "AS IS" BASIS,
23# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24# See the License for the specific language governing permissions and
25# limitations under the License.
27import atheris
28import sys
29with atheris.instrument_imports():
30 import ftfy
32def TestInput(data):
33 fdp = atheris.FuzzedDataProvider(data)
35 try:
36 ftfy.fix_text(fdp.ConsumeUnicodeNoSurrogates(100))
37 plan1 = ftfy.fix_and_explain(fdp.ConsumeUnicodeNoSurrogates(100))[1]
38 ftfy.apply_plan(fdp.ConsumeUnicodeNoSurrogates(100), plan1)
39 ftfy.fix_text_segment(fdp.ConsumeUnicodeNoSurrogates(100))
41 f = open("temp.txt", "w")
42 f.write(fdp.ConsumeUnicodeNoSurrogates(1000))
43 f.close()
44 f = open("temp.txt", "r")
45 ftfy.fix_file(f)
46 f.close()
48 ftfy.guess_bytes(fdp.ConsumeBytes(100))
49 except UnicodeEncodeError as e2:
50 pass
51 except UnicodeError as e:
52 if "Hey wait, this isn't Unicode." not in str(e):
53 raise e
55def main():
56 atheris.Setup(sys.argv, TestInput, enable_python_coverage=True)
57 atheris.Fuzz()
59if __name__ == "__main__":
60 main()