Found the issue with IndexOutOfBound exception.

Swapped mistakenly width and height all-sub-squares, tested before only
on the square input, where width and height were the same, so was not
able to spot the issue. All tests except one produce "correct" output
(just need to implement track of duplicates), the one with empty []
hangs, probably there is another issue somewhere.