Avoid potential infinite loop if unexpected EOF received from cat-file

Use read() method more defensively to avoid any chance of an infinite
loop in the (very unlikely) event an EOF is received mid-way through
some `cat-file` data.
Merge branch 'upstream' into improve_referenced_objects_performance
Merge branch 'upstream' into improve_referenced_objects_performance
Merge branch 'improve_referenced_objects_performance' of github:jmurty/git-fat (PR #37)

* 'improve_referenced_objects_performance' of github:jmurty/git-fat:
  Avoid potential infinite loop if unexpected EOF received from cat-file
Exit without ugly stack trace when run from outside a Git repository (fixes #45)

Reported-by: "Slavko"