AdvancedCustomFields / AdvancedCustomFields/acf
potential infinite loop in acf_get_field_ancestors()
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
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)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in acf-field-functions.php at acf_get_field_ancestors($field), then reproduce the issue with a field whose parent points to itself, such as {"name":"my_field","parent":"my_field"}. Done means recursive references no longer loop indefinitely and the function either returns the fields found before recursion or throws an exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100