Not sure why the file uses "SET KOI8-R" directive then?
This behavior occurs on: - Mac OS X 10.10 Yosemite and Mac OS X 10.11 El Capitan. - latest PostgreSQL version from git and PostgreSQL 9.5 (probably also on 9.4.5).
There is also the test to reproduce this bug in the attachment.
What error message do you get with this test program? (I don't get any, but I'm not on Mac OS.)