[Trivia] Obnoxious filenames break custom upload #5948

Closed
opened 2022-12-31 00:24:08 +01:00 by Flame442 · 2 comments
Flame442 commented 2022-12-31 00:24:08 +01:00 (Migrated from github.com)

What Red version are you using?

3.5.0.dev323+g23d539c4

Cog name

Trivia

Command name

triviaset custom upload

What did you expect to happen?

It to work.

What actually happened?

The command errored:

Traceback (most recent call last):
  File "venv\lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
  File "venv\lib\site-packages\redbot\cogs\trivia\trivia.py", line 279, in trivia_upload
    await self._save_trivia_list(ctx=ctx, attachment=parsedfile)
  File "venv\lib\site-packages\redbot\cogs\trivia\trivia.py", line 693, in _save_trivia_list
    with file.open("wb") as fp:
  File "Python\Python38\lib\pathlib.py", line 1218, in open
    return io.open(self, mode, buffering, encoding, errors, newline,
  File "Python\Python38\lib\pathlib.py", line 1074, in _opener
    return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'datapath\\cogs\\Trivia\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.yaml'

How can we reproduce this error?

  1. Create a valid trivia file with the name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.yaml
  2. Attempt to upload this file with [p]triviaset custom upload

Anything else?

This bug occurred on Windows, which has a limit to the length of the entire filepath, rather than a limit to the length of the filename. My datapath happens to be nested deeper than the place I made the file from, allowing me to give it a longer name than it could have in my datapath.

To fix this bug, the error should probably be caught with a message about the path being invalid. Limiting the filename technically will not fix this issue alone, as even a filename that is 1 character long could cause this error in extreme cases.

### What Red version are you using? 3.5.0.dev323+g23d539c4 ### Cog name Trivia ### Command name triviaset custom upload ### What did you expect to happen? It to work. ### What actually happened? The command errored: ```py Traceback (most recent call last): File "venv\lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped ret = await coro(*args, **kwargs) File "venv\lib\site-packages\redbot\cogs\trivia\trivia.py", line 279, in trivia_upload await self._save_trivia_list(ctx=ctx, attachment=parsedfile) File "venv\lib\site-packages\redbot\cogs\trivia\trivia.py", line 693, in _save_trivia_list with file.open("wb") as fp: File "Python\Python38\lib\pathlib.py", line 1218, in open return io.open(self, mode, buffering, encoding, errors, newline, File "Python\Python38\lib\pathlib.py", line 1074, in _opener return self._accessor.open(self, flags, mode) FileNotFoundError: [Errno 2] No such file or directory: 'datapath\\cogs\\Trivia\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.yaml' ``` ### How can we reproduce this error? 1. Create a valid trivia file with the name `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.yaml` 2. Attempt to upload this file with `[p]triviaset custom upload` ### Anything else? This bug occurred on Windows, which has a limit to the length of the entire filepath, rather than a limit to the length of the filename. My datapath happens to be nested deeper than the place I made the file from, allowing me to give it a longer name than it could have in my datapath. To fix this bug, the error should probably be caught with a message about the path being invalid. Limiting the filename technically will not fix this issue alone, as even a filename that is 1 character long *could* cause this error in extreme cases.
Stonedestroyer commented 2022-12-31 12:17:38 +01:00 (Migrated from github.com)

Technically we could support paths longer than 256 characters, but not sure if Python itself allows this, but if I do not misremember Python asks if you wanna increase max path size, or maybe it was a different program.

https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later

So it's a case if we wanna enable this if it's supported and keep it in our guide, or maybe just reference it incase the error is hit and the user wants to resolve it in the traceback rather. Then again enabling this may have drawbacks if other apps do not support longer path and there is no way to delete the file outside of Red.

Technically we could support paths longer than 256 characters, but not sure if Python itself allows this, but if I do not misremember Python asks if you wanna increase max path size, or maybe it was a different program. https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later So it's a case if we wanna enable this if it's supported and keep it in our guide, or maybe just reference it incase the error is hit and the user wants to resolve it in the traceback rather. Then again enabling this may have drawbacks if other apps do not support longer path and there is no way to delete the file outside of Red.
SaengerItsWar commented 2022-12-31 14:37:13 +01:00 (Migrated from github.com)

Python is asking about max path length.
https://docs.python.org/3/using/windows.html

Python is asking about max path length. https://docs.python.org/3/using/windows.html
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#5948
No description provided.