diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2019-09-23 12:41:35 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2019-09-23 13:17:23 +0200 |
commit | 97deff8278c8bed1ec448b9c30b8999c6a62fe03 (patch) | |
tree | 65c8184cc66936a073c61e03a0d3412edac3c704 | |
parent | 4d00bb40718ab4e01230e1492d73a2d92e0124f9 (diff) |
Detect enum store entry reference count overflow.
5 files changed, 14 insertions, 2 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp b/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp index 897d8a10ec6..b527f89b224 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp @@ -41,6 +41,7 @@ void EnumAttribute<B>::load_enum_store(LoadedVector& loaded) prev = value.getValue(); prevRefCount = 1; } else { + assert(prevRefCount < std::numeric_limits<uint32_t>::max()); prevRefCount++; } value.setEidx(index); diff --git a/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h b/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h index a8d6fc3ba68..275fadd1e7f 100644 --- a/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h +++ b/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h @@ -138,6 +138,7 @@ public: (void) docId; (void) weight; assert(e < _hist.size()); + assert(_hist[e] < std::numeric_limits<uint32_t>::max()); ++_hist[e]; } }; diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp index 21bbec729df..19ef92c9356 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp @@ -93,6 +93,7 @@ PostingListAttributeBase<P>::handle_load_posting_lists_and_update_enum_store(enu postings.clear(); } } + assert(refCount < std::numeric_limits<uint32_t>::max()); ++refCount; assert(elem.getDocId() < docIdLimit); (void) docIdLimit; diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_builder.h b/vespalib/src/vespa/vespalib/datastore/unique_store_builder.h index 7f5162d97ff..c0a44855063 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store_builder.h +++ b/vespalib/src/vespa/vespalib/datastore/unique_store_builder.h @@ -35,6 +35,7 @@ public: } EntryRef mapEnumValueToEntryRef(uint32_t enumValue) { assert(enumValue < _refs.size()); + assert(_refCounts[enumValue] < std::numeric_limits<uint32_t>::max()); ++_refCounts[enumValue]; return _refs[enumValue]; } diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_entry_base.h b/vespalib/src/vespa/vespalib/datastore/unique_store_entry_base.h index 2b5bff45d79..79ebae9389f 100644 --- a/vespalib/src/vespa/vespalib/datastore/unique_store_entry_base.h +++ b/vespalib/src/vespa/vespalib/datastore/unique_store_entry_base.h @@ -4,6 +4,8 @@ #include <cstring> #include <cstdint> +#include <cassert> +#include <limits> namespace search::datastore { @@ -20,8 +22,14 @@ protected: public: uint32_t get_ref_count() const { return _ref_count; } void set_ref_count(uint32_t ref_count) const { _ref_count = ref_count; } - void inc_ref_count() const { ++_ref_count; } - void dec_ref_count() const { --_ref_count; } + void inc_ref_count() const { + assert(_ref_count < std::numeric_limits<uint32_t>::max()); + ++_ref_count; + } + void dec_ref_count() const { + assert(_ref_count > 0u); + --_ref_count; + } }; } |