Skip to content

Infinite recursion in walk() when S3 bucket contains object with key / #953

Open

Description

@SamirAltos

We've run into a reproducible issue where calling walk() on an S3 bucket causes infinite recursion if the bucket contains an object with the key /

This happens because:

  • S3 allows an object to be created with the key /
  • ls() returns it as a "directory" (i.e. common prefix /)
  • walk() sees that as a subdirectory and recurses into it
  • But that "subdirectory" is just the bucket root again → leading to infinite recursion
  • This eventually leads to a RecursionError: maximum recursion depth exceeded.

Let us know if this is something you'd consider filtering out at the s3fs level. Happy to provide a test case or additional details!

Thanks for the great library 🙏

Activity

  1. martindurant commented on Mar 25, 2025

    @martindurant
    Member

    Hmm, the case of a key called simply "/" was clearly not considered or encountered so far. Can you get around the problem using find(), perhaps?

  2. itzzdev09 commented on Sep 16, 2026

    @itzzdev09

    On current main against moto, walk() no longer recurses, but a / key still shows up oddly: as bucket/ in ls and bucket// in find(withdirs=True). Is filtering that entry out something you would want? If so, I can open a PR.

  3. martindurant commented on Sep 16, 2026

    @martindurant
    Member

    Yes please - it should not be too complicated

  4. itzzdev09 commented on Sep 16, 2026

    @itzzdev09

    Opened #1043 for this. @martindurant

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions