Fix a regression from #38517 (the tail section index is not correctly assigned). And add a test to cover GetDiffForRender.