Index: src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexOutput.java
===================================================================
--- src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexOutput.java	(revision 925935)
+++ src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexOutput.java	(working copy)
@@ -21,11 +21,11 @@
  *  expected to give poor performance; it's really only for
  *  testing the pluggability.  One should typically use pfor instead. */
 
-import org.apache.lucene.util.CodecUtil;
+import java.io.IOException;
+
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexOutput;
-
-import java.io.IOException;
+import org.apache.lucene.util.CodecUtil;
 
 /**
  * Don't use this class!!  It naively encodes ints one vInt
@@ -39,16 +39,25 @@
   public final static int VERSION_START = 0;
   public final static int VERSION_CURRENT = VERSION_START;
 
-  public SimpleIntBlockIndexOutput(Directory dir, String fileName, int blockSize) throws IOException {
-    IndexOutput out = dir.createOutput(fileName);
+  public SimpleIntBlockIndexOutput(final Directory dir, final String fileName, final int blockSize) throws IOException {
+    final IndexOutput out = dir.createOutput(fileName);
     CodecUtil.writeHeader(out, CODEC, VERSION_CURRENT);
-    init(out, blockSize);
+    this.init(out, blockSize);
+  }
+
+  @Override
+  protected void flushBlock(final int[] buffer, final IndexOutput out) throws IOException {
+    this.flushBlock(buffer, buffer.length, out);
   }
 
   @Override
-  protected void flushBlock(int[] buffer, IndexOutput out) throws IOException {
+  protected void flushBlock(final int[] buffer, final int length, final IndexOutput out)
+  throws IOException {
     // silly impl
-    for(int i=0;i<buffer.length;i++) {
+    // write block length
+    out.writeVInt(length);
+    assert length <= buffer.length;
+    for(int i = 0; i < length; i++) {
       out.writeVInt(buffer[i]);
     }
   }
Index: src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexInput.java
===================================================================
--- src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexInput.java	(revision 925935)
+++ src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexInput.java	(working copy)
@@ -21,11 +21,11 @@
  *  expected to give poor performance; it's really only for
  *  testing the pluggability.  One should typically use pfor instead. */
 
-import org.apache.lucene.util.CodecUtil;
+import java.io.IOException;
+
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
-
-import java.io.IOException;
+import org.apache.lucene.util.CodecUtil;
 
 /**
  * Don't use this class!!  It naively encodes ints one vInt
@@ -35,10 +35,10 @@
  */
 public class SimpleIntBlockIndexInput extends FixedIntBlockIndexInput {
 
-  public SimpleIntBlockIndexInput(Directory dir, String fileName, int readBufferSize) throws IOException {
-    IndexInput in = dir.openInput(fileName, readBufferSize);
+  public SimpleIntBlockIndexInput(final Directory dir, final String fileName, final int readBufferSize) throws IOException {
+    final IndexInput in = dir.openInput(fileName, readBufferSize);
     CodecUtil.checkHeader(in, SimpleIntBlockIndexOutput.CODEC, SimpleIntBlockIndexOutput.VERSION_START);
-    init(in);
+    this.init(in);
   }
 
   private static class BlockReader implements FixedIntBlockIndexInput.BlockReader {
@@ -46,21 +46,24 @@
     private final IndexInput in;
     private final int[] buffer;
 
-    public BlockReader(IndexInput in, int[] buffer) {
+    public BlockReader(final IndexInput in, final int[] buffer) {
       this.in = in;
       this.buffer = buffer;
     }
 
     public void readBlock() throws IOException {
       // silly impl
-      for(int i=0;i<buffer.length;i++) {
+      // read block length
+      final int length = in.readVInt();
+      assert length <= buffer.length;
+      for(int i = 0; i < length; i++) {
         buffer[i] = in.readVInt();
       }
     }
   }
 
   @Override
-  protected BlockReader getBlockReader(IndexInput in, int[] buffer) {
+  protected BlockReader getBlockReader(final IndexInput in, final int[] buffer) {
     return new BlockReader(in, buffer);
   }
 }
Index: src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java
===================================================================
--- src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java	(revision 925935)
+++ src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java	(working copy)
@@ -41,7 +41,7 @@
   private int[] pending;
   private int upto;
 
-  protected void init(IndexOutput out, int fixedBlockSize) throws IOException {
+  protected void init(final IndexOutput out, final int fixedBlockSize) throws IOException {
     blockSize = fixedBlockSize;
     out.writeVInt(blockSize);
     this.out = out;
@@ -50,6 +50,8 @@
 
   protected abstract void flushBlock(int[] buffer, IndexOutput out) throws IOException;
 
+  protected abstract void flushBlock(int[] buffer, int length, IndexOutput out) throws IOException;
+
   @Override
   public Index index() throws IOException {
     return new Index();
@@ -73,14 +75,14 @@
     }
 
     @Override
-    public void set(IntIndexOutput.Index other) throws IOException {
-      Index idx = (Index) other;
+    public void set(final IntIndexOutput.Index other) throws IOException {
+      final Index idx = (Index) other;
       lastFP = fp = idx.fp;
       lastUpto = upto = idx.upto;
     }
 
     @Override
-    public void write(IndexOutput indexOut, boolean absolute) throws IOException {
+    public void write(final IndexOutput indexOut, final boolean absolute) throws IOException {
       if (absolute) {
         indexOut.writeVLong(fp);
         indexOut.writeVInt(upto);
@@ -89,7 +91,7 @@
         indexOut.writeVLong(0);
         assert upto >= lastUpto;
         indexOut.writeVLong(upto - lastUpto);
-      } else {      
+      } else {
         // new block
         indexOut.writeVLong(fp - lastFP);
         indexOut.writeVLong(upto);
@@ -100,10 +102,10 @@
   }
 
   @Override
-  public void write(int v) throws IOException {
+  public void write(final int v) throws IOException {
     pending[upto++] = v;
     if (upto == blockSize) {
-      flushBlock(pending, out);
+      this.flushBlock(pending, out);
       upto = 0;
     }
   }
@@ -114,7 +116,7 @@
       if (upto > 0) {
       // NOTE: entries in the block after current upto are
       // invalid
-        flushBlock(pending, out);
+        this.flushBlock(pending, upto, out);
       }
     } finally {
       out.close();
Index: src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java
===================================================================
--- src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java	(revision 925935)
+++ src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java	(working copy)
@@ -1,42 +1,63 @@
 package org.apache.lucene.index.codecs.intblock;
 
+import org.apache.lucene.index.codecs.sep.IntIndexInput;
+import org.apache.lucene.index.codecs.sep.IntIndexOutput;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.store.*;
-import org.apache.lucene.index.codecs.sep.*;
 
 public class TestIntBlockCodec extends LuceneTestCase {
 
   public void testSimpleIntBlocks() throws Exception {
-    Directory dir = new MockRAMDirectory();
+    final Directory dir = new MockRAMDirectory();
 
-    IntIndexOutput out = new SimpleIntBlockIndexOutput(dir, "test", 128);
+    final IntIndexOutput out = new SimpleIntBlockIndexOutput(dir, "test", 128);
     for(int i=0;i<11777;i++) {
       out.write(i);
     }
     out.close();
 
-    IntIndexInput in = new SimpleIntBlockIndexInput(dir, "test", 128);
-    IntIndexInput.Reader r = in.reader();
+    final IntIndexInput in = new SimpleIntBlockIndexInput(dir, "test", 128);
+    final IntIndexInput.Reader r = in.reader();
 
     for(int i=0;i<11777;i++) {
       assertEquals(i, r.next());
     }
     in.close();
-    
+
     dir.close();
   }
 
   public void testEmptySimpleIntBlocks() throws Exception {
-    Directory dir = new MockRAMDirectory();
+    final Directory dir = new MockRAMDirectory();
 
-    IntIndexOutput out = new SimpleIntBlockIndexOutput(dir, "test", 128);
+    final IntIndexOutput out = new SimpleIntBlockIndexOutput(dir, "test", 128);
     // write no ints
     out.close();
 
-    IntIndexInput in = new SimpleIntBlockIndexInput(dir, "test", 128);
-    IntIndexInput.Reader r = in.reader();
+    final IntIndexInput in = new SimpleIntBlockIndexInput(dir, "test", 128);
+    final IntIndexInput.Reader r = in.reader();
     // read no ints
     in.close();
     dir.close();
   }
+
+  public void testIncompleteSimpleIntBlocks() throws Exception {
+    final Directory dir = new MockRAMDirectory();
+
+    final IntIndexOutput out = new SimpleIntBlockIndexOutput(dir, "test", 128);
+    for(int i = 0; i < 42; i++) {
+      out.write(i);
+    }
+    out.close();
+
+    final IntIndexInput in = new SimpleIntBlockIndexInput(dir, "test", 128);
+    final IntIndexInput.Reader r = in.reader();
+    for(int i = 0; i < 42; i++) {
+      assertEquals(i, r.next());
+    }
+    in.close();
+    dir.close();
+  }
+
 }

