'r' in file operations is used only for reading text files but for other files 'rb' must be used.

... files 'rb' should be used