Check read error before checking read length.

Change-Id: Iad83dd3181addb88339fabdede6f4c2ad9d6380e