Fix Buffer Overrun messages for tiff files.

  While processing tiff tags, the end pointer was not updated after a
  realloc.
  Also, while processing IFD tag, end and begin pointers were switched.

This should fix #1154 (the second case there was added to test/slow/ext_image, I tested manually the first case and there's no segfault).