Check the palette for valid entries
Somehow, this code is more complex than I think it should be...
BUG:410387