Skip to content

[3.12] gh-98820: Fix quadratic time in csv.Sniffer for quoted fields (GH-154867) - #155166

Merged
Yhg1s merged 1 commit into
python:3.12from
serhiy-storchaka:backport-3.12-gh98820
Aug 4, 2026
Merged

[3.12] gh-98820: Fix quadratic time in csv.Sniffer for quoted fields (GH-154867)#155166
Yhg1s merged 1 commit into
python:3.12from
serhiy-storchaka:backport-3.12-gh98820

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Manual backport of #154867 to the security branch, cherry-picked from the 3.13 backport (commit b30c7fa).

The only conflict was in Lib/csv.py: 3.12 does not have gh-103925, so its patterns end with (?:$|\n) where the 3.13 pre-image had (?:$|\r|\n). After the resolution _guess_quote_and_delimiter() is identical to the 3.13 one.

Sniffing '"abcdefghijklmnopqrstuvwxyz"\n' * n with delimiters=',:|\t' takes 0.248, 0.977, 3.891 and 15.316 s for n = 1250, 2500, 5000 and 10000 before the change, and 0.026, 0.055, 0.109 and 0.216 s after it.

@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka and @Yhg1s, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 063d4555c94ef412c731527dbf30193327f2ee82 3.11

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka and @Yhg1s, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 063d4555c94ef412c731527dbf30193327f2ee82 3.10

@serhiy-storchaka
serhiy-storchaka deleted the backport-3.12-gh98820 branch August 4, 2026 19:03
@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Backports should be made after merging #155115 and #155116. Backport to 3.10 may be non-trivial, because possessive qualifiers are only supported since 3.11.

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

Labels

type-security A security issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants