Skip to content

fix(compiler): infinite loop in parser assignment expression with invalid left-hand expression#47151

Closed
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:47131/parser-infinite-loop
Closed

fix(compiler): infinite loop in parser assignment expression with invalid left-hand expression#47151
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:47131/parser-infinite-loop

Conversation

@crisbeto
Copy link
Member

In #39004 some logic was introduced that tries to recover invalid expressions by treating the = token as a recovery point. It works by skipping ahead to the next recovery point inside the skip method which is called whenever an error is reported. This can lead to an infinite loop inside the parseChain method which assumes that reporting an error would've skipped over the token, but that won't happen since the = token is a recovery point. These changes resolve the infinite loop by breaking the loop if error didn't skip to a different token after the error was reported.

Fixes #47131.

…alid left-hand expression

In angular#39004 some logic was introduced that tries to recover invalid expressions by treating the `=` token as a recovery point. It works by skipping ahead to the next recovery point inside the `skip` method which is called whenever an error is reported. This can lead to an infinite loop inside the `parseChain` method which assumes that reporting an error would've skipped over the token, but that won't happen since the `=` token is a recovery point. These changes resolve the infinite loop by breaking the loop if `error` didn't skip to a different token after the error was reported.

Fixes angular#47131.
// lead to an infinite loop. If that's the case, break the loop assuming that we can't
// parse further.
if (this.index === errorIndex) {
break;
Copy link
Member Author

Choose a reason for hiding this comment

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

I was on the fence between breaking the loop here and calling advance which would attempt to continue parsing. I went with this, because the example from the unit test would turn from (a[1] = b) = c = d into a[1] = b; c; d which didn't seem very useful. I don't feel strongly one way or the other so I'm open to changing it.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Aug 14, 2022
@ngbot ngbot bot modified the milestone: Backlog Aug 14, 2022
@crisbeto crisbeto marked this pull request as ready for review August 14, 2022 13:26
@pullapprove pullapprove bot requested a review from JoostK August 14, 2022 13:27
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

LGTM ✈️ (I'm waiting for a flight so a plane seems appropriate)

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 16, 2022
@ngbot

This comment was marked as outdated.

@pkozlowski-opensource
Copy link
Member

This PR was merged into the repository by commit dc52cef.

pkozlowski-opensource pushed a commit that referenced this pull request Aug 17, 2022
…alid left-hand expression (#47151)

In #39004 some logic was introduced that tries to recover invalid expressions by treating the `=` token as a recovery point. It works by skipping ahead to the next recovery point inside the `skip` method which is called whenever an error is reported. This can lead to an infinite loop inside the `parseChain` method which assumes that reporting an error would've skipped over the token, but that won't happen since the `=` token is a recovery point. These changes resolve the infinite loop by breaking the loop if `error` didn't skip to a different token after the error was reported.

Fixes #47131.

PR Close #47151
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Aug 23, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/animations](https://github.com/angular/angular) | dependencies | patch | [`14.1.2` -> `14.1.3`](https://renovatebot.com/diffs/npm/@angular%2fanimations/14.1.2/14.1.3) |
| [@angular/common](https://github.com/angular/angular) | dependencies | patch | [`14.1.2` -> `14.1.3`](https://renovatebot.com/diffs/npm/@angular%2fcommon/14.1.2/14.1.3) |
| [@angular/compiler](https://github.com/angular/angular) | dependencies | patch | [`14.1.2` -> `14.1.3`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/14.1.2/14.1.3) |
| [@angular/compiler-cli](https://github.com/angular/angular) | devDependencies | patch | [`14.1.2` -> `14.1.3`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/14.1.2/14.1.3) |
| [@angular/core](https://github.com/angular/angular) | dependencies | patch | [`14.1.2` -> `14.1.3`](https://renovatebot.com/diffs/npm/@angular%2fcore/14.1.2/14.1.3) |
| [@angular/forms](https://github.com/angular/angular) | dependencies | patch | [`14.1.2` -> `14.1.3`](https://renovatebot.com/diffs/npm/@angular%2fforms/14.1.2/14.1.3) |
| [@angular/platform-browser](https://github.com/angular/angular) | dependencies | patch | [`14.1.2` -> `14.1.3`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/14.1.2/14.1.3) |
| [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | patch | [`14.1.2` -> `14.1.3`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/14.1.2/14.1.3) |

---

### Release Notes

<details>
<summary>angular/angular</summary>

### [`v14.1.3`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1413-2022-08-17)

[Compare Source](angular/angular@14.1.2...14.1.3)

##### compiler

| Commit | Type | Description |
| -- | -- | -- |
| [0583227708](angular/angular@0583227) | fix | infinite loop in parser assignment expression with invalid left-hand expression ([#&#8203;47151](angular/angular#47151)) |

#### Special Thanks

AlirezaEbrahimkhani, Alma Eyre, Andrew Scott, Bob Watson, George Kalpakas, Kalbarczyk, Kristiyan Kostadinov, Leosvel Pérez Espinosa, Roman Matusevich and Sonu Kapoor

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xNjEuMCIsInVwZGF0ZWRJblZlciI6IjMyLjE2MS4wIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1512
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(compile) Parenthesized assignment in two-way ngModel binding causes out of memory error

4 participants