Skip to content

Submit the re, json, csv, & struct modules to oss-fuzz testing #73691

Closed

Description

@gpshead
BPO 29505
Nosy @brettcannon, @terryjreedy, @gpshead, @tiran, @ssbr, @alex, @bitdancer, @ammaraskar, @miss-islington
PRs
  • bpo-29505: Add fuzz tests for float(str), int(str), unicode(str) #2878
  • bpo-29505: Avoid UB in test selection macro. #3407
  • bpo-29505: Fuzz ast.parse() / compile() with PyCF_ONLY_AST #3437
  • bpo-29505: Fix interpreter in fuzzing targets to be relocatable #13907
  • [3.8] bpo-29505: Fix interpreter in fuzzing targets to be relocatable (GH-13907) #13914
  • [3.7] bpo-29505: Fix interpreter in fuzzing targets to be relocatable (GH-13907) #13915
  • bpo-29505: Fuzz json module, enforce size limit on int(x) fuzz #13991
  • [3.8] bpo-29505: Fuzz json module, enforce size limit on int(x) fuzz (GH-13991) #14005
  • [3.7] bpo-29505: Fuzz json module, enforce size limit on int(x) fuzz (GH-13991) #14006
  • bpo-29505: Add fuzzing for re.compile, re.load and csv.reader #14255
  • [3.8] bpo-29505: Add more fuzzing for re.compile, re.load and csv.reader (GH-14255) #14478
  • [3.7] bpo-29505: Add more fuzzing for re.compile, re.load and csv.reader (GH-14255) #14479
  • bpo-29505: Fuzz struct.unpack and catch RecursionError in re.compile #18679
  • bpo-29505: Add fuzzer for ast.literal_eval #28777
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/gpshead'
    closed_at = <Date 2021-04-02.16:05:39.827>
    created_at = <Date 2017-02-08.20:54:21.924>
    labels = ['type-security', '3.7']
    title = 'Submit the re, json, csv, & struct modules to oss-fuzz testing'
    updated_at = <Date 2021-10-06.23:22:19.809>
    user = 'https://github.com/gpshead'

    bugs.python.org fields:

    activity = <Date 2021-10-06.23:22:19.809>
    actor = 'miss-islington'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2021-04-02.16:05:39.827>
    closer = 'ammar2'
    components = []
    creation = <Date 2017-02-08.20:54:21.924>
    creator = 'gregory.p.smith'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29505
    keywords = ['patch']
    message_count = 29.0
    messages = ['287363', '287568', '292821', '293263', '293340', '299183', '299207', '301494', '301495', '301530', '301535', '301732', '301759', '301897', '301901', '301918', '301922', '301932', '345039', '345044', '345045', '345304', '345306', '345307', '346916', '346918', '347496', '390076', '403340']
    nosy_count = 10.0
    nosy_names = ['brett.cannon', 'terry.reedy', 'gregory.p.smith', 'christian.heimes', 'Devin Jeanpierre', 'alex', 'r.david.murray', 'Guido', 'ammar2', 'miss-islington']
    pr_nums = ['2878', '3407', '3437', '13907', '13914', '13915', '13991', '14005', '14006', '14255', '14478', '14479', '18679', '28777']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'security'
    url = 'https://bugs.python.org/issue29505'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7']

    Activity

    1. gpshead commented on Sep 9, 2017

      @gpshead
      MemberAuthor

      i'd rather make this work in oss-fuzz on cpython. can you point me to how oss-fuzz works and what it wants to do so i can better understand what it needs?

      it it has an expectation that the thing being fuzzed is a single binary with no data or directory tree layout dependencies that can just be plopped somewhere else is not a great assumption to make.

      but environment variables _should_ be able to be set to point the python binary at what it needs if it must work that way.

    2. ssbr commented on Sep 11, 2017

      ssbrmannequin
      Mannequin

      i'd rather make this work in oss-fuzz on cpython. can you point me to how oss-fuzz works and what it wants to do so i can better understand what it needs?

      I don't have any details except for what's in the PR to oss-fuzz (google/oss-fuzz#731) My understanding is matches what you've said so far:

      Python is built to one directory (/out/), but then needs to be run from another directory (/out/ is renamed to /foo/bar/baz/out/). We need python to still work. I have no idea how to do this.

      The only suggestion on #python-dev IRC was to statically link a libpython.a, but this doesn't avoid needing to import libraries like "encodings" dynamically, so they still need to be locatable on disk.

      Is there a way to build python so that it doesn't use absolute paths to everything, and so that the install can be moved at will? Or is there a way to tell it that it was moved at runtime? (I am unconvinced PYTHONPATH is a maintainable solution, if it works at all...)

      oss-fuzz is not going to change away from its model (I asked if they could, they said no), so we're stuck with making Python compatible with it one way or another. This is why I am so drawn to running the test internally on Google's infrastructure anyway: we already _did_ all this work already, via hermetic python. Doing it a second time, but worse, seems annoying.

    3. ssbr commented on Sep 11, 2017

      ssbrmannequin
      Mannequin

      kcc strongly disagrees though. Copying latest comment:

      """
      fwiw - I object to us running any of this internally at Google. We need to be part of the main oss-fuzz project pulling from upstream revisions. Doing this testing within our blackhole of internal stuff adds more work for us internally (read: which we're not going to do) and wouldn't provide results feedback to the upstream CPython project in a useful timely manner.

      We must figure out how to get this to build and run on the external oss-fuzz infrastructure
      """

    4. gpshead commented on Sep 11, 2017

      @gpshead
      MemberAuthor

      misquote. that was me objecting to running it internally. :)

      i believe this is solvable, i haven't had time to spend on this part yet.

    5. ssbr commented on Sep 11, 2017

      ssbrmannequin
      Mannequin

      Oops, so it is. I can't read apparently.

      I'll spend my time on making more fuzz tests in the meantime.

    6. bitdancer commented on Sep 12, 2017

      @bitdancer
      Member

      Seems like it ought to be possible to use the same hooks that venv uses to make this work, but I haven't looked at the details of how those work.

    7. gpshead commented on Jun 8, 2019

      @gpshead
      MemberAuthor

      New changeset a15a7bc by Gregory P. Smith (Ammar Askar) in branch 'master':
      bpo-29505: Fix interpreter in fuzzing targets to be relocatable (GH-13907)
      a15a7bc

    8. miss-islington commented on Jun 8, 2019

      @miss-islington
      Contributor

      New changeset 22b69da by Miss Islington (bot) in branch '3.8':
      bpo-29505: Fix interpreter in fuzzing targets to be relocatable (GH-13907)
      22b69da

    9. miss-islington commented on Jun 8, 2019

      @miss-islington
      Contributor

      New changeset 6692d35 by Miss Islington (bot) in branch '3.7':
      bpo-29505: Fix interpreter in fuzzing targets to be relocatable (GH-13907)
      6692d35

    10. gpshead commented on Jun 12, 2019

      @gpshead
      MemberAuthor

      New changeset a6e190e by Gregory P. Smith (Ammar Askar) in branch 'master':
      bpo-29505: Fuzz json module, enforce size limit on int(x) fuzz (GH-13991)
      a6e190e

    11. miss-islington commented on Jun 12, 2019

      @miss-islington
      Contributor

      New changeset 534136a by Miss Islington (bot) in branch '3.7':
      bpo-29505: Fuzz json module, enforce size limit on int(x) fuzz (GH-13991)
      534136a

    12. miss-islington commented on Jun 12, 2019

      @miss-islington
      Contributor

      New changeset 878227e by Miss Islington (bot) in branch '3.8':
      bpo-29505: Fuzz json module, enforce size limit on int(x) fuzz (GH-13991)
      878227e

    13. gpshead commented on Jun 30, 2019

      @gpshead
      MemberAuthor

      New changeset 5cbbbd7 by Gregory P. Smith (Ammar Askar) in branch 'master':
      bpo-29505: Add more fuzzing for re.compile, re.load and csv.reader (GH-14255)
      5cbbbd7

    14. miss-islington commented on Jun 30, 2019

      @miss-islington
      Contributor

      New changeset ffcc161 by Miss Islington (bot) in branch '3.8':
      bpo-29505: Add more fuzzing for re.compile, re.load and csv.reader (GH-14255)
      ffcc161

    15. Guido commented on Jul 8, 2019

      Guidomannequin
      Mannequin

      Hi,

      I've built a generic Python fuzzer and submitted it to OSS-Fuzz.

      It works by implementing a "def FuzzerRunOne(FuzzerInput):" function in Python in which some arbitrary code is run based on FuzzerInput, which is a bytes object.

      This is a more versatile solution than the current re, json, csv fuzzers as it requires no custom C code and adding more fuzzing targets is as easy as writing a new harness in Python and adding a build rule.

      Code coverage is measured at both the CPython level (.c) and the Python level (.py). CPython is compiled with AddressSanitizer. What this means is that both CPython memory bugs and Python library bugs (excessive memory consumption, hangs, slowdowns, unexpected exceptions) are expected to transpire.

      You can see my current set of fuzzers here: https://github.com/guidovranken/python-library-fuzzers

      The PR to OSS-Fuzz is google/oss-fuzz#2567

      Currently, the only Python maintainer who will be receiving automated bug reports is gpshead. Are there any other developers who normally process Python security bug reports and would like to receive notifications?

      Feel free to respond directly in the OSS-Fuzz PR thread.

    16. changed the title [-]Submit the re, json, & csv modules to oss-fuzz testing[/-] [+]Submit the re, json, csv, & struct modules to oss-fuzz testing[/+] on Feb 28, 2020
    17. ammaraskar commented on Apr 2, 2021

      @ammaraskar
      Member

      All the modules prescribed in the original bug are now actively being fuzzed, thank you to Devin for the original work on this and Gregory for reviewing all these changes.

      I'm closing this now, feel free to make a new bug and nosy me in if there are any other C-based modules commonly exposed to user input that should be fuzzed.

    18. miss-islington commented on Oct 6, 2021

      @miss-islington
      Contributor

      New changeset db72e58 by Ammar Askar in branch 'main':
      bpo-29505: Add fuzzer for ast.literal_eval (GH-28777)
      db72e58

    19. transferred this issue fromon Apr 10, 2022
    20. added a commit that references this issue on Nov 3, 2022
    21. gpshead commented on Nov 24, 2024

      @gpshead
      MemberAuthor

      In anybody has a clone of the, now former https://github.com/guidovranken/python-library-fuzzers repo. Please let us know. The author has deleted their project.

    22. alex commented on Nov 24, 2024

      @alex
      Member

      @gpshead has anyone emailed Guido? If not, I'm happy to.

    23. gpshead commented on Nov 24, 2024

      @gpshead
      MemberAuthor

      I emailed them earlier today. But we've since turned up copies so I think we're all good now to figure out if we want to keep running that.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions