Skip to content

Refuse overlong gem filenames - #586

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/gem-filename-length
Oct 24, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/gem-filename-length

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

parseGemFilename tries every -<digit> in a gem filename as the start of the version and matches the rest against two patterns each time, so its cost grows with the square of the filename's length. A /gems/ path of a few hundred kilobytes kept a request busy for minutes, and the parse doesn't watch the request context.

Gem filenames longer than 512 bytes are now answered with 400 before parsing. Real gem filenames are far shorter. TestGemDownloadRefusesLongFilename sends a 900 KB name and expects 400 within 5 seconds; before this change it didn't finish.

parseGemFilename tries every "-<digit>" in the filename as the start of the version and matches the rest against two patterns each time, so its cost grows with the square of the filename's length. A path of a few hundred kilobytes kept a request busy for minutes, and the parse doesn't watch the request context.

Gem filenames longer than 512 bytes are now answered with 400 before parsing. Real ones are far shorter.
@andrew
andrew merged commit 562ffb3 into git-pkgs:main Oct 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants