Index: /trunk/Ohana/src/libohana/src/IOBufferOps.c
===================================================================
--- /trunk/Ohana/src/libohana/src/IOBufferOps.c	(revision 23552)
+++ /trunk/Ohana/src/libohana/src/IOBufferOps.c	(revision 23553)
@@ -27,5 +27,5 @@
 int ReadtoIOBuffer (IOBuffer *buffer, int fd) {
 
-  int Nread, Nfree;
+  int Nread, Nfree, Nwant;
 
   if (fd == 0) {
@@ -34,4 +34,5 @@
   }
 
+  // if we run out of space, double Nblock
   Nfree = buffer[0].Nalloc - buffer[0].Nbuffer;
   if (Nfree < buffer[0].Nblock) {
@@ -44,6 +45,8 @@
   }
 
-  Nread = read (fd, &buffer[0].buffer[buffer[0].Nbuffer], buffer[0].Nblock);
-  if (DEBUG) fprintf (stderr, "read IO buffer: (%lx) %d from %d\n", (unsigned long) buffer, Nread, buffer[0].Nblock); 
+  // ensure we never read more than space available
+  Nwant = MIN (Nfree, buffer[0].Nblock);
+  Nread = read (fd, &buffer[0].buffer[buffer[0].Nbuffer], Nwant);
+  if (DEBUG) fprintf (stderr, "read IO buffer: (%lx) %d from %d\n", (unsigned long) buffer, Nread, Nwant); 
 
   /* on success, increase the block size for the next read */
