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

potential infinite loop in acf_get_field_ancestors() #898

Open
jhard opened this issue Feb 25, 2024 · 0 comments
Open

potential infinite loop in acf_get_field_ancestors() #898

jhard opened this issue Feb 25, 2024 · 0 comments

Comments

@jhard
Copy link

jhard commented Feb 25, 2024

acf_get_field_ancestors($field) (acf-field-functions.php) can cause an infinite loop if the field setup is broken and includes a recursive reference.

To Reproduce
Set up a field as {"name": "my_field", "parent": "my_field"}
call acf_get_field_ancestors($field)

Expected behavior
Returns the fields found until recursion is encountered (or throws an exception upon recursion).

// Loop over parents.
while ( $field['parent'] && $field = acf_get_field( $field['parent'] ) ) {
        $ancestors[] = $field['ID'] ? $field['ID'] : $field['key'];
} 

This part would need a check whether the ID/key is already included, i.e.

// Loop over parents.
while ( $field['parent'] && $field = acf_get_field( $field['parent'] ) ) {
    $idOrKey = $field['ID'] ? $field['ID'] : $field['key'];
    if(in_array($idOrKey, $ancestors, true)) {
        break;
    }
    $ancestors[] = $idOrKey;
} 

Version Information:

  • WP Version 6.4.3
  • PHP 8.0.18
  • ACF PRO 6.2.5 (problem still exists in current version)
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

No branches or pull requests

1 participant