Add test of corruption detection, fix related bug