Fix an issue with more than 64k deps, spotted by maximuska.

Also add a test for this case, which would have spotted the issue too.
Merge pull request #645 from nico/maximfix

Fix an issue with more than 64k deps, spotted by maximuska.