From ae49250942f4395639961abeed3c15920fcd7241 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= <piponazo@gmail.com>
Date: Sun, 4 Nov 2018 18:44:38 +0100
Subject: [PATCH] Check in Image::printIFDStructure if seek and reads are OK

---
 src/image.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/image.cpp b/src/image.cpp
index e0eebf3d4..75991f7d5 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -344,8 +344,11 @@ namespace Exiv2 {
 
         do {
             // Read top of directory
-            io.seek(start,BasicIo::beg);
-            io.read(dir.pData_, 2);
+            const int seekSuccess = !io.seek(start,BasicIo::beg);
+            const long bytesRead = io.read(dir.pData_, 2);
+            if (!seekSuccess || bytesRead == 0) {
+                throw Error(kerCorruptedMetadata);
+            }
             uint16_t   dirLength = byteSwap2(dir,0,bSwap);
 
             bool tooBig = dirLength > 500;
