diff options
Diffstat (limited to 'searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp')
-rw-r--r-- | searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp b/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp index a25766fcc71..fd812708ebc 100644 --- a/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp +++ b/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp @@ -4,6 +4,7 @@ #include <vespa/searchlib/query/tree/predicate_query_term.h> #include <vespa/vespalib/util/compress.h> #include <vespa/vespalib/objects/nbo.h> +#include <cassert> using search::query::PredicateQueryTerm; @@ -58,8 +59,7 @@ SimpleQueryStackDumpIterator::~SimpleQueryStackDumpIterator() = default; vespalib::stringref SimpleQueryStackDumpIterator::read_stringref(const char *&p) { - uint64_t len; - p += vespalib::compress::Integer::decompressPositive(len, p); + uint64_t len = readCompressedPositiveInt(p); if ((p + len) > _bufEnd) throw false; vespalib::stringref result(p, len); p += len; @@ -69,9 +69,24 @@ SimpleQueryStackDumpIterator::read_stringref(const char *&p) uint64_t SimpleQueryStackDumpIterator::readCompressedPositiveInt(const char *&p) { + if (p > _bufEnd || !vespalib::compress::Integer::check_decompress_space(p, _bufEnd - p)) { + throw false; + } uint64_t tmp; p += vespalib::compress::Integer::decompressPositive(tmp, p); - if (p > _bufEnd) throw false; + assert(p <= _bufEnd); + return tmp; +} + +int64_t +SimpleQueryStackDumpIterator::readCompressedInt(const char *&p) +{ + if (p > _bufEnd || !vespalib::compress::Integer::check_decompress_positive_space(p, _bufEnd - p)) { + throw false; + } + int64_t tmp; + p += vespalib::compress::Integer::decompress(tmp, p); + assert(p <= _bufEnd); return tmp; } @@ -98,11 +113,8 @@ bool SimpleQueryStackDumpIterator::readNext() { _currType = ParseItem::GetType(typefield); if (ParseItem::GetFeature_Weight(typefield)) { - int64_t tmpLong; - if (p >= _bufEnd) return false; - p += vespalib::compress::Integer::decompress(tmpLong, p); + int64_t tmpLong = readCompressedInt(p); _currWeight.setPercent(tmpLong); - if (p > _bufEnd) return false; } else { _currWeight.setPercent(100); } |