Merge pull request #29203 from CurtizJ/fix-ubsan

Fix integer underflow in function `quantile`
This commit is contained in:
Anton Popov 2021-10-02 20:36:53 +03:00 committed by GitHub
commit b64bbb54aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View File

@ -237,7 +237,7 @@ struct QuantileExactInclusive : public QuantileExact<Value>
nth_element(array.begin() + prev_n, array.begin() + n - 1, array.end()); nth_element(array.begin() + prev_n, array.begin() + n - 1, array.end());
auto nth_elem = std::min_element(array.begin() + n, array.end()); auto nth_elem = std::min_element(array.begin() + n, array.end());
result[indices[i]] = static_cast<Float64>(array[n - 1]) + (h - n) * static_cast<Float64>(*nth_elem - array[n - 1]); result[indices[i]] = static_cast<Float64>(array[n - 1]) + (h - n) * (static_cast<Float64>(*nth_elem) - array[n - 1]);
prev_n = n - 1; prev_n = n - 1;
} }
} }

View File

@ -0,0 +1 @@
[-1717986918.2,1.8]

View File

@ -0,0 +1,6 @@
SELECT
arrayMap(y -> round(y, 1), quantilesExactInclusive(0.1, 0.9)(x)) AS q
FROM
(
SELECT arrayJoin([-2147483648, 1, 2]) AS x
);