Skip to content

Break out of typealias cycles#1446

Merged
krzysztofzablocki merged 2 commits into
masterfrom
eh/fix-typealias-cycle
Nov 17, 2025
Merged

Break out of typealias cycles#1446
krzysztofzablocki merged 2 commits into
masterfrom
eh/fix-typealias-cycle

Conversation

@erichoracek

Copy link
Copy Markdown
Collaborator

When there’s a typealias cycle, we currently loop infinitely and eventually consume all system memory and crash.

When there’s a typealias cycle, we currently loop infinitely and eventually consume all system memory and crash.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an infinite loop vulnerability that occurs when typealiases form a cycle (e.g., typealias Foo = Bar and typealias Bar = Foo), which previously caused the system to consume all memory and crash. The fix implements cycle detection using a visited set to track aliases during resolution and breaks out of the loop when a cycle is detected, logging a warning instead.

Key Changes:

  • Added cycle detection logic in typealias resolution to prevent infinite loops
  • Added test coverage for typealias cycle scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
SourceryRuntime/Sources/Common/Composer/ParserResultsComposed.swift Implements cycle detection by tracking visited alias names in a Set and breaking the loop when a cycle is detected, with a warning log
SourceryTests/Parsing/ComposerSpec.swift Adds test case to verify the system handles typealias cycles without looping infinitely

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread SourceryRuntime/Sources/Common/Composer/ParserResultsComposed.swift Outdated
@krzysztofzablocki krzysztofzablocki merged commit 71b6b50 into master Nov 17, 2025
2 checks passed
@krzysztofzablocki krzysztofzablocki deleted the eh/fix-typealias-cycle branch November 17, 2025 13:31
@krzysztofzablocki

Copy link
Copy Markdown
Owner

thanks @erichoracek

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.

3 participants