Skip to content

gh-136073: Fix expandvars() in Tools/freeze/checkextensions.py - #136093

Open
serhiy-storchaka wants to merge 3 commits into
python:mainfrom
serhiy-storchaka:tool-freeze-checkextensions-expandvars
Open

gh-136073: Fix expandvars() in Tools/freeze/checkextensions.py#136093
serhiy-storchaka wants to merge 3 commits into
python:mainfrom
serhiy-storchaka:tool-freeze-checkextensions-expandvars

Conversation

@serhiy-storchaka

@serhiy-storchakaserhiy-storchaka commented Jun 29, 2025

Copy link
Copy Markdown
Member
  • Fix potential infinite recursion and/or memory consumption.
  • Fix a bug when reference can cross boundaries of substitutions, e.g. expandvars('$a)', {'a': '$(b', 'b': 'c'}).
  • Fix potential quadratic complexity.

* Fix potential infinite recursion and/or memory consumption.
* Fix a bug when reference can cross boundaries of substitutions, e.g.
expandvars('$a)', {'a': '$(b', 'b': 'c'}).
* Fix potential quadratic complexity.
@kexinoh

Copy link
Copy Markdown

I just realized that the newly discovered code still has some issues, such as when constructing the following example as input:

def generate_bomb_vars(depth):
vars_dict = {'v0': 'X'}
for i in range(1, depth + 1):
vars_dict[f'v{i}'] = f'$(v{i-1})$(v{i-1})'
target_str = f'$(v{depth})'
return target_str, vars_dict

@serhiy-storchaka

Copy link
Copy Markdown
MemberAuthor

The new version is optimized, it returns the result much faster for depth=20 and depth=30. But note that for depth=30 the result takes 1 GiB, and for depth=60 it requires the amount of memory larger than the mainstream computers support. The code will produce the result as fast as it can, but it cannot do anything if the result cannot fit in a memory.

This is similar to a billion laughs attack. The only way to treat it is to impose an artificial application specific limit on the result size. If this was a code facing an external world, it would be an issue. But this is an internal function in an internal tool. It is only used with data generated by other parts of the tool.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Apr 26, 2026
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 30, 2026
@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label Jun 1, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core reviewneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesneeds backport to 3.15pre-release feature fixes, bugs and security fixesskip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@serhiy-storchaka@kexinoh