I have a patch that add some consistency checks and fixes this issue.
Created attachment 21586 [details] patch
Comment on attachment 21586 [details] patch r=me
Committed revision 34496.