From 132d377474e52bebeaaabe71543930684ea6fb95 Mon Sep 17 00:00:00 2001 From: PG Date: Wed, 6 Dec 2017 12:17:05 +0530 Subject: [PATCH 1/4] [LUCENE-8075] Possible null pointer dereference in core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java Fix it --- .../codecs/blocktree/IntersectTermsEnum.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java index 19e56a40a04d..1e1b05481515 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java @@ -106,37 +106,37 @@ public IntersectTermsEnum(FieldReader fr, Automaton automaton, RunAutomaton runA if (fr.index == null) { fstReader = null; } else { - fstReader = fr.index.getBytesReader(); - } - - // TODO: if the automaton is "smallish" we really - // should use the terms index to seek at least to - // the initial term and likely to subsequent terms - // (or, maybe just fallback to ATE for such cases). - // Else the seek cost of loading the frames will be - // too costly. - - final FST.Arc arc = fr.index.getFirstArc(arcs[0]); - // Empty string prefix must have an output in the index! - assert arc.isFinal(); - - // Special pushFrame since it's the first one: - final IntersectTermsEnumFrame f = stack[0]; - f.fp = f.fpOrig = fr.rootBlockFP; - f.prefix = 0; - f.setState(0); - f.arc = arc; - f.outputPrefix = arc.output; - f.load(fr.rootCode); - - // for assert: - assert setSavedStartTerm(startTerm); - - currentFrame = f; - if (startTerm != null) { - seekToStartTerm(startTerm); + fstReader = fr.index.getBytesReader(); + + // TODO: if the automaton is "smallish" we really + // should use the terms index to seek at least to + // the initial term and likely to subsequent terms + // (or, maybe just fallback to ATE for such cases). + // Else the seek cost of loading the frames will be + // too costly. + + final FST.Arc arc = fr.index.getFirstArc(arcs[0]); + // Empty string prefix must have an output in the index! + assert arc.isFinal(); + + // Special pushFrame since it's the first one: + final IntersectTermsEnumFrame f = stack[0]; + f.fp = f.fpOrig = fr.rootBlockFP; + f.prefix = 0; + f.setState(0); + f.arc = arc; + f.outputPrefix = arc.output; + f.load(fr.rootCode); + + // for assert: + assert setSavedStartTerm(startTerm); + + currentFrame = f; + if (startTerm != null) { + seekToStartTerm(startTerm); + } + currentTransition = currentFrame.transition; } - currentTransition = currentFrame.transition; } // only for assert: From 113f76f86f5b5c3e929fa3c976f89bfd3a4a9984 Mon Sep 17 00:00:00 2001 From: Pulak Ghosh Date: Sun, 7 Jan 2018 01:44:29 +0530 Subject: [PATCH 2/4] Update IntersectTermsEnum.java --- .../codecs/blocktree/IntersectTermsEnum.java | 65 +++++++++---------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java index 1e1b05481515..139e2e8043f5 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java @@ -103,40 +103,37 @@ public IntersectTermsEnum(FieldReader fr, Automaton automaton, RunAutomaton runA arcs[arcIdx] = new FST.Arc<>(); } - if (fr.index == null) { - fstReader = null; - } else { - fstReader = fr.index.getBytesReader(); - - // TODO: if the automaton is "smallish" we really - // should use the terms index to seek at least to - // the initial term and likely to subsequent terms - // (or, maybe just fallback to ATE for such cases). - // Else the seek cost of loading the frames will be - // too costly. - - final FST.Arc arc = fr.index.getFirstArc(arcs[0]); - // Empty string prefix must have an output in the index! - assert arc.isFinal(); - - // Special pushFrame since it's the first one: - final IntersectTermsEnumFrame f = stack[0]; - f.fp = f.fpOrig = fr.rootBlockFP; - f.prefix = 0; - f.setState(0); - f.arc = arc; - f.outputPrefix = arc.output; - f.load(fr.rootCode); - - // for assert: - assert setSavedStartTerm(startTerm); - - currentFrame = f; - if (startTerm != null) { - seekToStartTerm(startTerm); - } - currentTransition = currentFrame.transition; - } + + fstReader = fr.index.getBytesReader(); + + // TODO: if the automaton is "smallish" we really + // should use the terms index to seek at least to + // the initial term and likely to subsequent terms + // (or, maybe just fallback to ATE for such cases). + // Else the seek cost of loading the frames will be + // too costly. + + final FST.Arc arc = fr.index.getFirstArc(arcs[0]); + // Empty string prefix must have an output in the index! + assert arc.isFinal(); + + // Special pushFrame since it's the first one: + final IntersectTermsEnumFrame f = stack[0]; + f.fp = f.fpOrig = fr.rootBlockFP; + f.prefix = 0; + f.setState(0); + f.arc = arc; + f.outputPrefix = arc.output; + f.load(fr.rootCode); + + // for assert: + assert setSavedStartTerm(startTerm); + + currentFrame = f; + if (startTerm != null) { + seekToStartTerm(startTerm); + } + currentTransition = currentFrame.transition } // only for assert: From 32b943c8f01d7be892bbc2993c71358ac2092f90 Mon Sep 17 00:00:00 2001 From: Pulak Ghosh Date: Sun, 7 Jan 2018 01:46:53 +0530 Subject: [PATCH 3/4] Update IntersectTermsEnum.java --- .../org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java index 139e2e8043f5..487a73408d55 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java @@ -133,7 +133,7 @@ public IntersectTermsEnum(FieldReader fr, Automaton automaton, RunAutomaton runA if (startTerm != null) { seekToStartTerm(startTerm); } - currentTransition = currentFrame.transition + currentTransition = currentFrame.transition; } // only for assert: From 70fd6d88bd1da75e5b80512144db116fed60bbfd Mon Sep 17 00:00:00 2001 From: Pulak Ghosh Date: Sun, 7 Jan 2018 01:49:31 +0530 Subject: [PATCH 4/4] Update IntersectTermsEnum.java --- .../codecs/blocktree/IntersectTermsEnum.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java index 487a73408d55..7521763f3304 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/IntersectTermsEnum.java @@ -113,27 +113,27 @@ public IntersectTermsEnum(FieldReader fr, Automaton automaton, RunAutomaton runA // Else the seek cost of loading the frames will be // too costly. - final FST.Arc arc = fr.index.getFirstArc(arcs[0]); - // Empty string prefix must have an output in the index! - assert arc.isFinal(); - - // Special pushFrame since it's the first one: - final IntersectTermsEnumFrame f = stack[0]; - f.fp = f.fpOrig = fr.rootBlockFP; - f.prefix = 0; - f.setState(0); - f.arc = arc; - f.outputPrefix = arc.output; - f.load(fr.rootCode); - - // for assert: - assert setSavedStartTerm(startTerm); - - currentFrame = f; - if (startTerm != null) { - seekToStartTerm(startTerm); - } - currentTransition = currentFrame.transition; + final FST.Arc arc = fr.index.getFirstArc(arcs[0]); + // Empty string prefix must have an output in the index! + assert arc.isFinal(); + + // Special pushFrame since it's the first one: + final IntersectTermsEnumFrame f = stack[0]; + f.fp = f.fpOrig = fr.rootBlockFP; + f.prefix = 0; + f.setState(0); + f.arc = arc; + f.outputPrefix = arc.output; + f.load(fr.rootCode); + + // for assert: + assert setSavedStartTerm(startTerm); + + currentFrame = f; + if (startTerm != null) { + seekToStartTerm(startTerm); + } + currentTransition = currentFrame.transition; } // only for assert: