Skip to content
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

Infinite recursion when Content Picker Field references its own parent item with displaying shape override #16218

Open
Piedone opened this issue Jun 3, 2024 · 2 comments
Labels
Milestone

Comments

@Piedone
Copy link
Member

Piedone commented Jun 3, 2024

Describe the bug

You can create an infinite recursion if you pick the parent item itself in a Content Picker Field.

To Reproduce

Steps to reproduce the behavior:

  1. Add Content Picker Field to a content type, allowing the content type itself to be selected (e.g. you add it to Page, and let Page items be picked too).
  2. Create a content item, publish, edit again, pick the content item itself, publish.
  3. By default, this doesn't cause an issue, because the ContentPicker shape only lists the display texts of the picked items. However, if you have an override that DisplayAsync()s the picked items, see below, you can produce an infinite loop, crashing the process.
@model OrchardCore.ContentFields.ViewModels.DisplayContentPickerFieldViewModel
@using OrchardCore.ContentManagement
@using OrchardCore.ContentManagement.Display
@using OrchardCore.DisplayManagement.ModelBinding
@using OrchardCore.Mvc.Utilities
@using OrchardCore.ContentManagement.Metadata.Models

@inject IContentManager ContentManager
@inject IContentItemDisplayManager DisplayManager
@inject IUpdateModelAccessor UpdateModelAccessor

@{
    var contentItems = await ContentManager.GetAsync(Model.ContentItemIds);

    foreach (var contentItem in contentItems)
    {
        <span>This is new:</span>
        @(await DisplayAsync(await DisplayManager.BuildDisplayAsync(contentItem, UpdateModelAccessor.ModelUpdater)))
    }
}

Latest main (8e3c818).

Expected behavior

This is clearly a misconfiguration that can't produce much sensible, but still, the app shouldn't crash. So, e.g.:

  • An error message is displayed on the frontend in place of the picked items.
  • Don't let such picked items be saved in the first place. This might be just part of the solution though, since due to indirections (picked item within picked item...) and dynamic inclusions this can't necessarily be determined.

Screenshots

@sebastienros
Copy link
Member

In Fluid there is MaxSteps and MaxRecursion to limit the execution of templates.

@Piedone Piedone changed the title Infinite loop when Content Picker Field references its own parent item with displaying shape override Infinite recursion when Content Picker Field references its own parent item with displaying shape override Jun 6, 2024
@sebastienros sebastienros added this to the 2.x milestone Jun 6, 2024
Copy link
Contributor

github-actions bot commented Jun 6, 2024

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants