diff --git a/be/src/vec/columns/column_string.cpp b/be/src/vec/columns/column_string.cpp index af0b7e14c366de..af2378fd02d3b0 100644 --- a/be/src/vec/columns/column_string.cpp +++ b/be/src/vec/columns/column_string.cpp @@ -40,8 +40,8 @@ template void ColumnStr::sanity_check() const { #ifndef NDEBUG sanity_check_simple(); - auto count = cast_set(offsets.size()); - for (int i = 0; i < count; ++i) { + auto count = cast_set(offsets.size()); + for (int64_t i = 0; i < count; ++i) { if (offsets[i] < offsets[i - 1]) { throw Exception(Status::InternalError("row count: {}, offsets[{}]: {}, offsets[{}]: {}", count, i, offsets[i], i - 1, offsets[i - 1])); @@ -53,7 +53,7 @@ void ColumnStr::sanity_check() const { template void ColumnStr::sanity_check_simple() const { #ifndef NDEBUG - auto count = cast_set(offsets.size()); + auto count = cast_set(offsets.size()); if (chars.size() != offsets[count - 1]) { throw Exception(Status::InternalError("row count: {}, chars.size(): {}, offset[{}]: {}", count, chars.size(), count - 1, offsets[count - 1])); @@ -157,7 +157,15 @@ void ColumnStr::insert_range_from_ignore_overflow(const doris::vectorized::IC src_concrete.offsets[start + i] - nested_offset + prev_max_offset; } } - sanity_check_simple(); + +#ifndef NDEBUG + auto count = cast_set(offsets.size()); + // offsets may overflow, so we make chars.size() as T to do same overflow check + if (offsets.back() != T(chars.size())) { + throw Exception(Status::InternalError("row count: {}, chars.size(): {}, offset[{}]: {}", + count, chars.size(), count - 1, offsets[count - 1])); + } +#endif } template