Possible infinite loop in EasyBreadcrumbBuilder.php when 'Breadcrumb segment coun' is set to a negative value or is set to 0.

Patch needed.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

drupalfan2 created an issue. See original summary.

drupalfan2’s picture

Issue summary: View changes
drupalfan2’s picture

The following patch avoids the infinite while loop.

sriram s made their first commit to this issue’s fork.

sriram_s’s picture

Status: Active » Needs review

Opened MR !167 to fix this.

Root cause: with "limit segment display" on, a segment count of 0 and the
home segment included, $segment_limit is decremented to -1; the trimming
loop condition count($links) > $segment_limit is then always true and
loops infinitely. A negative value entered directly hits the same path.

Fix: clamp the limit with max(0, $segment_limit) immediately before the
loop, which covers both the 0-with-home-segment case and directly-entered
negative values (broader than the original patch, which guarded only the
home-segment branch).

Tested on Drupal 11.4 / easy_breadcrumb 2.0.9: reproduced the hang with
segment count = 0 + home segment enabled, confirmed the page loads after
the fix, and verified a valid positive limit still trims correctly.

Note: the phpcs pipeline failures are pre-existing coding-standard issues
in files unrelated to this change (src/TitleResolver.php,
easy_breadcrumb.install, .tugboat/config.yml). This MR only edits
src/EasyBreadcrumbBuilder.php; the phpunit and phpstan jobs pass. Happy to
open a separate MR for the standards cleanup if wanted.

Thanks @drupalfan2 for the report and diagnosis.

greg boggs’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • greg boggs committed f9086f08 on 2.x authored by sriram s
    Issue #3503872 by sriram, drupalfan2: Guard breadcrumb segment limit...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.