mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-17 20:02:05 +00:00
Fix UBSan report in GatherUtils #19287
This commit is contained in:
parent
1bb8cc5c9a
commit
110089086b
@ -342,7 +342,7 @@ void NO_INLINE sliceDynamicOffsetUnbounded(Source && src, Sink && sink, const IC
|
||||
if (offset > 0)
|
||||
slice = src.getSliceFromLeft(offset - 1);
|
||||
else
|
||||
slice = src.getSliceFromRight(-offset);
|
||||
slice = src.getSliceFromRight(-UInt64(offset));
|
||||
|
||||
writeSlice(slice, sink);
|
||||
}
|
||||
@ -374,7 +374,7 @@ void NO_INLINE sliceDynamicOffsetBounded(Source && src, Sink && sink, const ICol
|
||||
Int64 size = has_length ? length_nested_column->getInt(row_num) : static_cast<Int64>(src.getElementSize());
|
||||
|
||||
if (size < 0)
|
||||
size += offset > 0 ? static_cast<Int64>(src.getElementSize()) - (offset - 1) : -offset;
|
||||
size += offset > 0 ? static_cast<Int64>(src.getElementSize()) - (offset - 1) : -UInt64(offset);
|
||||
|
||||
if (offset != 0 && size > 0)
|
||||
{
|
||||
@ -383,7 +383,7 @@ void NO_INLINE sliceDynamicOffsetBounded(Source && src, Sink && sink, const ICol
|
||||
if (offset > 0)
|
||||
slice = src.getSliceFromLeft(offset - 1, size);
|
||||
else
|
||||
slice = src.getSliceFromRight(-offset, size);
|
||||
slice = src.getSliceFromRight(-UInt64(offset), size);
|
||||
|
||||
writeSlice(slice, sink);
|
||||
}
|
||||
|
10
tests/queries/0_stateless/01658_substring_ubsan.sql
Normal file
10
tests/queries/0_stateless/01658_substring_ubsan.sql
Normal file
@ -0,0 +1,10 @@
|
||||
/** NOTE: The behaviour of substring and substringUTF8 is inconsistent when negative offset is greater than string size:
|
||||
* substring:
|
||||
* hello
|
||||
* ^-----^ - offset -10, length 7, result: "he"
|
||||
* substringUTF8:
|
||||
* hello
|
||||
* ^-----^ - offset -10, length 7, result: "hello"
|
||||
* This may be subject for change.
|
||||
*/
|
||||
SELECT substringUTF8('hello, пÑ<C2BF>ивеÑ<C2B5>', -9223372036854775808, number) FROM numbers(16) FORMAT Null;
|
Loading…
Reference in New Issue
Block a user