fix(toolbox): prevent invalid tile indexing in toolbox overlap calculation#17131
fix(toolbox): prevent invalid tile indexing in toolbox overlap calculation#17131Harxhit wants to merge 1 commit intojitsi:masterfrom
Conversation
|
Hi, thanks for your contribution! |
What does this fix? How to reproduce? |
The issue happens when noOfTilesToCheck is larger than the number of rendered tiles. for (let i = 1; i < Math.max(noOfTilesToCheck, tiles.length); i++) Math.max(7, 3) becomes 7, so the loop runs 6 iterations even though only 3 tiles exist. const tile = tiles[tiles.length - i]; becomes: tiles[3 - 4] → undefined which results in accessing .querySelector() on an invalid tile reference. const limit = Math.min(noOfTilesToCheck, tiles.length); ensuring the loop only iterates over existing tiles. |
1 similar comment
The issue happens when noOfTilesToCheck is larger than the number of rendered tiles. for (let i = 1; i < Math.max(noOfTilesToCheck, tiles.length); i++) Math.max(7, 3) becomes 7, so the loop runs 6 iterations even though only 3 tiles exist. const tile = tiles[tiles.length - i]; becomes: tiles[3 - 4] → undefined which results in accessing .querySelector() on an invalid tile reference. const limit = Math.min(noOfTilesToCheck, tiles.length); ensuring the loop only iterates over existing tiles. |
|
But how did you test it with the UI, what settings did you change to be able to reproduce the issue? How do you test it was fixed? |
How to reproduce the bug
Loop ran 8 times instead of the intended 4. We were checking tiles we never needed to.
Logs: Fix applied After fix (same 9-participant case) : Exactly 4 tiles checked. No over-iteration. No negative indices. Safe and correct. If helpful, I can also attach screenshots of the console logs showing the reproduction case and the behavior after applying the fix. |
|
This patch improves the toolbox overlap detection logic in
react/features/toolbox/subscriber.web.ts.
Changes:
Prevent invalid tile indexing
The loop used Math.max(noOfTilesToCheck, tiles.length), which could cause
negative indexing when noOfTilesToCheck exceeded the number of tiles.
The iteration limit is now bounded using Math.min(...) to ensure only
valid tile indexes are accessed.
Add document guard
A guard for the document object was added to prevent potential runtime
issues in environments where document may be undefined (e.g., testing).
Improve TypeScript readability
Added HTMLSpanElement typing for querySelectorAll to improve type
inference and readability.