From 433535b656961aaa938eef6e47cf06cc7334f137 Mon Sep 17 00:00:00 2001
From: David Gow <davidgow@google.com>
Date: Tue, 16 Dec 2014 12:02:46 +0000
Subject: [PATCH] Fix my_b_seek() after reading to end of IO_CACHE

If my_b_read() hits the end of file, future seeks may not work, as the
position in the buffer is not updated correctly, causing small seeks to
reuse the buffer even if it contains the wrong data. This patch sets
seek_not_done when a read error (such as end-of-file) occures, forcing a real
seek on the next read.
---
 mysys/mf_iocache.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index a3cbaff..e2d947b 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -507,6 +507,7 @@ int _my_b_read(register IO_CACHE *info, uchar *Buffer, size_t Count)
     {
       /* End of file. Return, what we did copy from the buffer. */
       info->error= (int) left_length;
+      info->seek_not_done= 1;
       DBUG_RETURN(1);
     }
     /*
@@ -524,6 +525,7 @@ int _my_b_read(register IO_CACHE *info, uchar *Buffer, size_t Count)
       */
       info->error= (read_length == (size_t) -1 ? -1 :
 		    (int) (read_length+left_length));
+      info->seek_not_done= 1;
       DBUG_RETURN(1);
     }
     Count-=length;
@@ -572,6 +574,7 @@ int _my_b_read(register IO_CACHE *info, uchar *Buffer, size_t Count)
     /* For a read error, return -1, otherwise, what we got in total. */
     info->error= length == (size_t) -1 ? -1 : (int) (length+left_length);
     info->read_pos=info->read_end=info->buffer;
+    info->seek_not_done= 1;
     DBUG_RETURN(1);
   }
   /*
-- 
2.8.0.rc3.226.g39d4020

