Index: lucene/core/src/test/org/apache/lucene/index/Test2BPositions.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/Test2BPositions.java	(revision 0)
+++ lucene/core/src/test/org/apache/lucene/index/Test2BPositions.java	(working copy)
@@ -0,0 +1,109 @@
+package org.apache.lucene.index;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.store.BaseDirectoryWrapper;
+import org.apache.lucene.store.MockDirectoryWrapper;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TimeUnits;
+import org.apache.lucene.util._TestUtil;
+import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
+
+import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
+
+/**
+ * Test indexes ~82M docs with 52 positions each, so you get > Integer.MAX_VALUE positions
+ * @lucene.experimental
+ */
+@SuppressCodecs({ "SimpleText", "Memory", "Direct" })
+@TimeoutSuite(millis = 4 * TimeUnits.HOUR)
+public class Test2BPositions extends LuceneTestCase {
+
+  @Nightly
+  public void test() throws Exception {
+    BaseDirectoryWrapper dir = newFSDirectory(_TestUtil.getTempDir("2BPositions"));
+    if (dir instanceof MockDirectoryWrapper) {
+      ((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
+    }
+    
+    IndexWriter w = new IndexWriter(dir,
+        new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
+        .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH)
+        .setRAMBufferSizeMB(256.0)
+        .setMergeScheduler(new ConcurrentMergeScheduler())
+        .setMergePolicy(newLogMergePolicy(false, 10))
+        .setOpenMode(IndexWriterConfig.OpenMode.CREATE));
+
+    MergePolicy mp = w.getConfig().getMergePolicy();
+    if (mp instanceof LogByteSizeMergePolicy) {
+     // 1 petabyte:
+     ((LogByteSizeMergePolicy) mp).setMaxMergeMB(1024*1024*1024);
+    }
+
+    Document doc = new Document();
+    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
+    ft.setOmitNorms(true);
+    Field field = new Field("field", new MyTokenStream(), ft);
+    doc.add(field);
+    
+    final int numDocs = (Integer.MAX_VALUE / 26) + 1;
+    for (int i = 0; i < numDocs; i++) {
+      w.addDocument(doc);
+      if (VERBOSE && i % 100000 == 0) {
+        System.out.println(i + " of " + numDocs + "...");
+      }
+    }
+    w.forceMerge(1);
+    w.close();
+    dir.close();
+  }
+  
+  public static final class MyTokenStream extends TokenStream {
+    private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+    private final PositionIncrementAttribute posIncAtt = addAttribute(PositionIncrementAttribute.class);
+    int index;
+
+    public MyTokenStream() {
+      termAtt.setLength(1);
+      termAtt.buffer()[0] = 'a';
+    }
+    
+    @Override
+    public boolean incrementToken() {
+      if (index < 52) {
+        posIncAtt.setPositionIncrement(1+index);
+        index++;
+        return true;
+      }
+      return false;
+    }
+    
+    @Override
+    public void reset() {
+      index = 0;
+    }
+  }
+}

Property changes on: lucene/core/src/test/org/apache/lucene/index/Test2BPositions.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
Index: lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsWriter.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsWriter.java	(revision 1396049)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsWriter.java	(working copy)
@@ -350,10 +350,10 @@
     public final long docStartFP;
     public final long posStartFP;
     public final long payStartFP;
-    public final int skipOffset;
-    public final int lastPosBlockOffset;
+    public final long skipOffset;
+    public final long lastPosBlockOffset;
 
-    public PendingTerm(long docStartFP, long posStartFP, long payStartFP, int skipOffset, int lastPosBlockOffset) {
+    public PendingTerm(long docStartFP, long posStartFP, long payStartFP, long skipOffset, long lastPosBlockOffset) {
       this.docStartFP = docStartFP;
       this.posStartFP = posStartFP;
       this.payStartFP = payStartFP;
@@ -397,7 +397,7 @@
       }
     }
 
-    final int lastPosBlockOffset;
+    final long lastPosBlockOffset;
 
     if (fieldHasPositions) {
       // if (DEBUG) {
@@ -411,7 +411,7 @@
       assert stats.totalTermFreq != -1;
       if (stats.totalTermFreq > BLOCK_SIZE) {
         // record file offset for last pos in last block
-        lastPosBlockOffset = (int) (posOut.getFilePointer() - posTermStartFP);
+        lastPosBlockOffset = posOut.getFilePointer() - posTermStartFP;
       } else {
         lastPosBlockOffset = -1;
       }
@@ -474,9 +474,9 @@
       lastPosBlockOffset = -1;
     }
 
-    int skipOffset;
+    long skipOffset;
     if (docCount > BLOCK_SIZE) {
-      skipOffset = (int) (skipWriter.writeSkip(docOut) - docTermStartFP);
+      skipOffset = skipWriter.writeSkip(docOut) - docTermStartFP;
       
       // if (DEBUG) {
       //   System.out.println("skip packet " + (docOut.getFilePointer() - (docTermStartFP + skipOffset)) + " bytes");
@@ -534,7 +534,7 @@
         bytesWriter.writeVLong(term.posStartFP - lastPosStartFP);
         lastPosStartFP = term.posStartFP;
         if (term.lastPosBlockOffset != -1) {
-          bytesWriter.writeVInt(term.lastPosBlockOffset);
+          bytesWriter.writeVLong(term.lastPosBlockOffset);
         }
         if ((fieldHasPayloads || fieldHasOffsets) && term.payStartFP != -1) {
           bytesWriter.writeVLong(term.payStartFP - lastPayStartFP);
@@ -543,7 +543,7 @@
       }
 
       if (term.skipOffset != -1) {
-        bytesWriter.writeVInt(term.skipOffset);
+        bytesWriter.writeVLong(term.skipOffset);
       }
     }
 
Index: lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java	(revision 1396049)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java	(working copy)
@@ -145,8 +145,8 @@
     long docStartFP;
     long posStartFP;
     long payStartFP;
-    int skipOffset;
-    int lastPosBlockOffset;
+    long skipOffset;
+    long lastPosBlockOffset;
 
     // Only used by the "primary" TermState -- clones don't
     // copy this (basically they are "transient"):
@@ -226,7 +226,7 @@
       if (fieldHasPositions) {
         termState.posStartFP = in.readVLong();
         if (termState.totalTermFreq > BLOCK_SIZE) {
-          termState.lastPosBlockOffset = in.readVInt();
+          termState.lastPosBlockOffset = in.readVLong();
         } else {
           termState.lastPosBlockOffset = -1;
         }
@@ -241,7 +241,7 @@
       if (fieldHasPositions) {
         termState.posStartFP += in.readVLong();
         if (termState.totalTermFreq > BLOCK_SIZE) {
-          termState.lastPosBlockOffset = in.readVInt();
+          termState.lastPosBlockOffset = in.readVLong();
         } else {
           termState.lastPosBlockOffset = -1;
         }
@@ -257,7 +257,7 @@
     }
 
     if (termState.docFreq > BLOCK_SIZE) {
-      termState.skipOffset = in.readVInt();
+      termState.skipOffset = in.readVLong();
     } else {
       termState.skipOffset = -1;
     }
@@ -344,7 +344,7 @@
     // Where this term's skip data starts (after
     // docTermStartFP) in the .doc file (or -1 if there is
     // no skip data for this term):
-    private int skipOffset;
+    private long skipOffset;
 
     // docID for next skip point, we won't use skipper if 
     // target docID is not larger than this
@@ -621,7 +621,7 @@
     // Where this term's skip data starts (after
     // docTermStartFP) in the .doc file (or -1 if there is
     // no skip data for this term):
-    private int skipOffset;
+    private long skipOffset;
 
     private int nextSkipDoc;
 
@@ -1035,7 +1035,7 @@
     // Where this term's skip data starts (after
     // docTermStartFP) in the .doc file (or -1 if there is
     // no skip data for this term):
-    private int skipOffset;
+    private long skipOffset;
 
     private int nextSkipDoc;
 
Index: lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsFormat.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsFormat.java	(revision 1396060)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsFormat.java	(working copy)
@@ -130,8 +130,8 @@
  *   <li>Term Metadata --&gt; DocFPDelta, PosFPDelta?, PosVIntBlockFPDelta?, PayFPDelta?, 
  *                            SkipFPDelta?</li>
  *   <li>Header, --&gt; {@link CodecUtil#writeHeader CodecHeader}</li>
- *   <li>PackedBlockSize, PosVIntBlockFPDelta, SkipFPDelta --&gt; {@link DataOutput#writeVInt VInt}</li>
- *   <li>DocFPDelta, PosFPDelta, PayFPDelta --&gt; {@link DataOutput#writeVLong VLong}</li>
+ *   <li>PackedBlockSize --&gt; {@link DataOutput#writeVInt VInt}</li>
+ *   <li>DocFPDelta, PosFPDelta, PayFPDelta, PosVIntBlockFPDelta, SkipFPDelta --&gt; {@link DataOutput#writeVLong VLong}</li>
  * </ul>
  * <p>Notes:</p>
  * <ul>
