Skip to content

bug: infinite loop risk in duplicate filename check #7

@LudoLoops

Description

@LudoLoops

Issue

In task/create.go:81-92, the filename uniqueness check has no upper limit.

for i := 1; ; i++ {  // ← No break condition!
    if _, err := os.Stat(filePath); os.IsNotExist(err) {
        break
    }
    // Increments forever if all filenames are taken
}

Problem

  • If thousands of files with same name exist, loop never terminates
  • No safeguard against edge case
  • Can hang application

Solution

Add a reasonable limit:

const maxDuplicateAttempts = 100
for i := 1; i <= maxDuplicateAttempts; i++ {
    if _, err := os.Stat(filePath); os.IsNotExist(err) {
        break
    }
}
if i > maxDuplicateAttempts {
    return "", "", fmt.Errorf("too many duplicate filenames")
}

Impact

🟡 Medium - Unlikely edge case but dangerous

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