Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.36.0
Description
SUBSTRING function with minimal possible integer offset parameter raise exception.
Simple way to reproduce :
append into SqlOperatorTest smth like:
f.checkScalar( String.format("{fn SUBSTRING('abcdef', %d)}", Integer.MIN_VALUE), "abcdef", "VARCHAR(6) NOT NULL");
And exception will raised:
String index out of range: -2147483641
it`s all due to integer overflow, check implementation near:
public static String substring(String c, int s) { final int s0 = s - 1; // -2147483648 - 1 = 2147483647 if (s0 <= 0) { // this check is broken return c; } if (s > c.length()) { return ""; } return c.substring(s0); }
Attachments
Issue Links
- relates to
-
CALCITE-4427 Make SUBSTRING operator comply with ISO standard SQL
- Closed
- links to