EDIT2: This discussion was reduced to "are collisions actually harder to create when you add a length constraint?" which is more relevant to the Crypto exchange. I will create a question there and link it when it exists. Thanks for everyone who participated in the discussion
EDIT: The term "Collision attack" in Wikipedia seems to only talk about finding any random collision, I meant to say "Preimage attack".
It would seem like a good idea to me, because it would prevent all collision attacks that require the attacker to modify the length of the data. The attacker would have to find a collision with the exact same length, which is obviously much harder than finding a general collision.
Collision attacks usually require the attacker to modify the length of the data (by appending more blocks to the existing data or something like that), don't they?
The only downside I see to this is that it will require the hash results to be longer (the way I see it only by 2-4 bytes being "The length of the data modulo 2^16-2^32" should be about enough) so not by much.
This of course doesn't have to be part of the hash function itself, it could just be a general security recommendation: "Verify the expected length of the data, not just that it matches the calculated hash, to prevent many forms of collision attacks".
Though I've never heard this recommendation said or mentioned before, even though the way I see it, it makes a lot of sense.
So, in general, I'm asking here: Why is this not a good idea? Should it be encoded in hash functions so it's automatically applied by anyone using those functions, or should it be a general security recommendation that is up to the user of the hash function to implement on his own, separately from the hash function?
Or maybe I'm completely missing something that makes this idea ridiculous?