From c9e267f9481c9631d9112411a6473db41230ec53 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 19 Jun 2015 19:54:02 +0000 Subject: [PATCH] LUCENE-6591: never write a negative vlong git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1686495 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 3 +++ .../src/java/org/apache/lucene/store/DataOutput.java | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index fb1edea43b6..0f3fdffe418 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -158,6 +158,9 @@ Bug fixes * LUCENE-6593: Fixed ToChildBlockJoinQuery's scorer to not refuse to advance to a document that belongs to the parent space. (Adrien Grand) +* LUCENE-6591: Never write a negative vLong (Robert Muir, Ryan Ernst, + Adrien Grand, Mike McCandless) + Changes in Runtime Behavior * LUCENE-6501: The subreader structure in ParallelCompositeReader diff --git a/lucene/core/src/java/org/apache/lucene/store/DataOutput.java b/lucene/core/src/java/org/apache/lucene/store/DataOutput.java index 4daf284be17..efdba774694 100644 --- a/lucene/core/src/java/org/apache/lucene/store/DataOutput.java +++ b/lucene/core/src/java/org/apache/lucene/store/DataOutput.java @@ -221,12 +221,14 @@ public abstract class DataOutput { * @see DataInput#readVLong() */ public final void writeVLong(long i) throws IOException { - assert i >= 0L; - writeNegativeVLong(i); + if (i < 0) { + throw new IllegalArgumentException("cannot write negative vLong (got: " + i + ")"); + } + writeSignedVLong(i); } - // write a pontentially negative vLong - private void writeNegativeVLong(long i) throws IOException { + // write a potentially negative vLong + private void writeSignedVLong(long i) throws IOException { while ((i & ~0x7FL) != 0L) { writeByte((byte)((i & 0x7FL) | 0x80L)); i >>>= 7; @@ -241,7 +243,7 @@ public abstract class DataOutput { * @see DataInput#readZLong() */ public final void writeZLong(long i) throws IOException { - writeNegativeVLong(BitUtil.zigZagEncode(i)); + writeSignedVLong(BitUtil.zigZagEncode(i)); } /** Writes a string.