We have a Debian with Debian kernel 2.6.18-5-686, filesystem ext3.

There is a directory dir1 owned by user1:user1
access flags: drwxrwx---

Now we have a user2 belonging to group user1
It should certainly have access to the dir1, however, instead it gets
"access denied" on cd and ls. It seems related to the fact that user2
belongs to too many groups (23 groups) and this is one of the last
groups in numbering order, so Linux gets confused.

But please note that
groups user2
also returns user1 among the groups of user2 (one of the last groups,
because they are ordered based on the GID)

Another very significant fact is that if user2 does
sg user1
then it is able to access dir1!!

Have you seen any such behaviour or have an idea of what can have happened?

For now the workaround we use is that this user always has to do "sg
user1" in order to get in there. But in this way the new files are
created with that group and this is not what we would like to happen.