decoder: properly handle EOF