Skip to content

gh-134873: Fix a DOS issue in idlelib #134874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

johnzhou721
Copy link
Contributor

@johnzhou721 johnzhou721 commented May 29, 2025

A DOS by Quadratic complexity issue is fixed in idlelib. Part of (but does not fix) #134873.

@terryjreedy terryjreedy moved this to In Progress in IDLE Issues May 29, 2025
@terryjreedy terryjreedy self-assigned this May 29, 2025
@terryjreedy
Copy link
Member

I believe that the 6 lines from 1205 to 1210 can be replaced by 2 lines -- an re.match and an f-string. I will submit an alternate proposal later. I believe that the input vevent name should have either no <>s or 2 of each, with maybe the latter for back compatibility (I will test). But I will may stick with the more general code to not break buggy extensions.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this is the fix that we go with, let's add a test case.

@ZeroIntensity ZeroIntensity added type-security A security issue needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels May 29, 2025
@johnzhou721
Copy link
Contributor Author

johnzhou721 commented May 29, 2025 via email

@johnzhou721
Copy link
Contributor Author

johnzhou721 commented May 29, 2025 via email

@kexinoh
Copy link

kexinoh commented May 30, 2025

@johnzhou721
I would greatly appreciate it if you could kindly address the issue located at

cpython/Lib/idlelib/editor.py

Lines 1373 to 1378 in 5ab66a8

while True:
chars = chars[:-1]
ncharsdeleted = ncharsdeleted + 1
have = len(chars.expandtabs(tabwidth))
if have <= want or chars[-1] not in " \t":
break
. I sincerely apologize for overlooking this in my previous message.

As an example, I successfully utilized Gemini 2.5 Pro to generate a reasonable fix for this problem. Could you give it a try?

@johnzhou721
Copy link
Contributor Author

@kexinoh Yes, I would give it a try once I have time; however, I am working on something else right now -- is it acceptable if I delay this by about a day or so?

(if anyone else has a fix ready before I get to this, feel free to make a pr onto the branch of my pr and I'll merge it into my PR)

…dziqkQ.rst

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@johnzhou721
Copy link
Contributor Author

@kexinoh I have a small amount of time not enough to work on anything else before I end my day so I attempted the issue you pointed out -- but can't test though.

@johnzhou721
Copy link
Contributor Author

Assuming this is the fix that we go with, let's add a test case.

Where? How? For what? Thanks! @ZeroIntensity

@ZeroIntensity
Copy link
Member

Where? How? For what?

We need a test case in test_idlelib that results in DOS/extreme slowness off main. Basically, just do something to prove that this PR fixes it (probably just testing with large amounts of data).

@johnzhou721
Copy link
Contributor Author

Wait... all platforms are failing EXCEPT the one I have access to...

@johnzhou721

This comment was marked as resolved.

@johnzhou721
Copy link
Contributor Author

Never mind...

@johnzhou721
Copy link
Contributor Author

I've fixed the issues -- is macOS 14 not using --slow-ci?

Anyways, I just scrubbed the ncharsdeleted stuff in the function and calculate it manually using length differences.

@bedevere-bot I have made the requested changes, please review again

@johnzhou721
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Jun 1, 2025

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz June 1, 2025 23:34
@picnixz picnixz dismissed their stale review June 1, 2025 23:35

Changes were made, but I'll review it tomorrow (or later this week, I'll be offline for a few days).

@picnixz picnixz removed their request for review June 2, 2025 09:47
@picnixz
Copy link
Member

picnixz commented Jun 2, 2025

(I'm removing the request until I have time)

@zware
Copy link
Member

zware commented Jun 2, 2025

Sidenote: I have a very hard time believing that there is any reasonable DOS in this code at all. Can someone please explain how it can be exploited?

@johnzhou721
Copy link
Contributor Author

@zware Maybe have a huge indentwidth and carefully configured string of whitespaces so that want gets very small?

@serhiy-storchaka
Copy link
Member

Did you test it with real file in IDLE, not just by calling delete_trail_char_and_space()? I afraid that you will get hard time just displaying a long line containing 10000 tabulations and 10000 spaces.

@johnzhou721
Copy link
Contributor Author

@serhiy will do. Yes the dos is very non exploitable and not sure if idle is used in production anyways but since it’s reported let sfix

@zware
Copy link
Member

zware commented Jun 4, 2025

I disagree. If it is non-exploitable, it's not a DOS. Fixing it only encourages further reports of invulnerable vulnerabilities and a waste of volunteer time.

That said, there does appear to be some opportunity for cleanup here. My objection is to classifying the change as "fixing a DOS" rather than to using cleaner code, at the maintainer (@terryjreedy and/or @serhiy-storchaka)'s discretion.

@ZeroIntensity ZeroIntensity removed type-security A security issue needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jun 4, 2025
@johnzhou721
Copy link
Contributor Author

@zware Good point! If so, we'll remove the fix for the have and want thing and only focus on the .lstrip and .rstrip part for <<<<...>>>>> since that makes the code cleaner. The have and want trimming space thing only reduces the time by a factor of the indent width at best which wouldn't be very high

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

7 participants