Fix StackOverflowError deleting a bookmark folder with a relation cycle - #9704
Open
Asgabani wants to merge 1 commit into
Open
Fix StackOverflowError deleting a bookmark folder with a relation cycle#9704Asgabani wants to merge 1 commit into
Asgabani wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 69f35ac. Configure here.
Author
|
Hello Team, Please check the changes and if you satisfied with the changes , approve them and let me help make our duckduckgo better Thank you |
traverseBranch() walked the folder tree with unbounded recursion and no cycle detection. If the relations table ever contains a folder cycle (corrupted data), it recurses forever and crashes with a StackOverflowError. Replaces the recursion with an iterative traversal guarded by a visited set, so a cycle is skipped instead of looped over indefinitely. Fixes duckduckgo#5928
Asgabani
force-pushed
the
fix/bookmark-folder-cycle-stackoverflow-5928
branch
from
September 4, 2026 14:59
69f35ac to
e17b41d
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #5928.
RealSavedSitesRepository.traverseBranch()walked the bookmark folder tree via unbounded recursion, with no protection against a cycle in the relations table. If the relations table ever ends up with a folder cycle (corrupted/inconsistent data), traversal recurses forever and the app crashes with aStackOverflowError— matching the reported crash trace, which showstraverseBranchrecursing repeatedly during a folder delete.Fix
Replaces the recursive traversal with an iterative one (
ArrayDeque+ a visited-folderSet), so a folder that's already been visited is skipped instead of revisited indefinitely. Traversal order/output is unchanged for normal (acyclic) folder trees.Test plan
whenFolderRelationsContainACycleThenGetFolderBranchTerminatesWithoutDuplicates, which inserts a corrupted cyclic relation (folderA ↔ folderB) directly via the DAOs and assertsgetFolderBranchterminates and returns each folder exactly once.SavedSitesRepositoryTestsuite (65 tests) — all pass, including every existinggetFolderBranch/deleteFolderBranchtest.spotlessApplyrun, diff is clean.Note
Low Risk
Localized change to private folder traversal with a regression test; behavior for valid trees is intended to stay the same while only corrupt cyclic data is handled differently.
Overview
Fixes #5928 by hardening bookmark folder branch traversal when the relations table contains a folder cycle (corrupted data), which previously caused unbounded recursion and a
StackOverflowErrorduring operations like folder delete that callgetFolderBranch.RealSavedSitesRepository.traverseBranch()is changed from recursive depth-first walking to an iterativeArrayDequeloop with a visited-folder set, so already-seen folder IDs are skipped instead of re-entered forever. Acyclic trees should behave the same; cycles terminate with each folder listed once.Adds
whenFolderRelationsContainACycleThenGetFolderBranchTerminatesWithoutDuplicates, seeding a cyclic folderA ↔ folderB relation via DAOs and assertinggetFolderBranchcompletes with expected folder and bookmark counts.Reviewed by Cursor Bugbot for commit e17b41d. Bugbot is set up for automated code reviews on this repo. Configure here.