Skip to content

gh-162867: Make ftplib.parse227 parsing linear for malformed replies - #162872

Closed
Sakibpedia wants to merge 1 commit into
python:mainfrom
Sakibpedia:fix-gh-162867-parse227-linear
Closed

Sakibpedia wants to merge 1 commit into
python:mainfrom
Sakibpedia:fix-gh-162867-parse227-linear

Conversation

@Sakibpedia

@Sakibpedia Sakibpedia commented Nov 30, 2026 •

Copy link
Copy Markdown

Fixes #162867.

ftplib.parse227() used a regex whose six greedy \d+ groups caused the matcher to retry at every digit of a long run when a reply did not contain six comma-separated numbers. Parsing time therefore grew quadratically with the length of the reply. Adding a digit-boundary guard to the pattern makes the search linear while preserving the set of accepted replies.

Tests cover a valid reply with a long octet and a malformed long reply.

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@picnixz

picnixz commented Nov 30, 2026

Copy link
Copy Markdown
Member

The OP clearly said "I'd be happy to submit a PR to address this."

@picnixz picnixz added the AI-guidelines-not-met The contribution does not meet our guidelines for using AI tools and is closed automatically. label Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-guidelines-not-met The contribution does not meet our guidelines for using AI tools and is closed automatically. awaiting review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quadratic parsing time in ftplib.parse227()

2 participants