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.