Ildar Absalyamov has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/1509
Change subject: Fix for integer numeric overflow in int* constructors ...................................................................... Fix for integer numeric overflow in int* constructors Change-Id: I0cb3411bf9a808ee87f4938c60804a8d267c36d0 --- A asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.1.ddl.aql A asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.2.ddl.aql A asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.3.query.aql A asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.1.ddl.aql A asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.2.ddl.aql A asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.3.ddl.aql A asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.4.ddl.aql A asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.5.ddl.aql A asterixdb/asterix-app/src/test/resources/runtimets/results/types/domain_boundaries/domain_boundaries.1.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java 13 files changed, 338 insertions(+), 9 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/09/1509/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.1.ddl.aql new file mode 100644 index 0000000..0885da1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.1.ddl.aql @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +drop dataverse test if exists; +create dataverse test; + +use dataverse test; + +create type Type as open { + id: int64, + int8: int8, + int16: int16, + int32: int32, + int64: int64 +} + +create dataset TestDS(Type) primary key id; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.2.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.2.ddl.aql new file mode 100644 index 0000000..551f658 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.2.ddl.aql @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +use dataverse test; + +insert into dataset TestDS( +{ + "id": 1, + "int8": int8("-128"), + "int16": int16("-32768"), + "int32": int32("-2147483648"), + "int64": int64("-9223372036854775808") +}) + +insert into dataset TestDS( +{ + "id": 2, + "int8": int8("127"), + "int16": int16("32767"), + "int32": int32("2147483647"), + "int64": int64("9223372036854775807") +}) \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.3.query.aql new file mode 100644 index 0000000..1b11312 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries/domain_boundaries.3.query.aql @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + for $x in dataset test.TestDS return $x; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.1.ddl.aql new file mode 100644 index 0000000..3aacd8f --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.1.ddl.aql @@ -0,0 +1,29 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +drop dataverse test if exists; +create dataverse test; + +use dataverse test; + +create type Type as open { + id: int64 +} + +create dataset TestDS(Type) primary key id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.2.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.2.ddl.aql new file mode 100644 index 0000000..8ae6438 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.2.ddl.aql @@ -0,0 +1,46 @@ + + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +drop dataverse test if exists; +create dataverse test; + +use dataverse test; + +create type Type as open { + id: int64, + int8: int8, + int16: int16, + int32: int32, + int64: int64 +} + +create dataset TestDS(Type) primary key id; + +insert into dataset TestDS( +{ + "id": 1, + "int8": int8("-129") +}) + +insert into dataset TestDS( +{ + "id": 2, + "int8": int8("128") +}) \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.3.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.3.ddl.aql new file mode 100644 index 0000000..1aaf98c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.3.ddl.aql @@ -0,0 +1,46 @@ + + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +drop dataverse test if exists; +create dataverse test; + +use dataverse test; + +create type Type as open { + id: int64, + int8: int8, + int16: int16, + int32: int32, + int64: int64 +} + +create dataset TestDS(Type) primary key id; + +insert into dataset TestDS( +{ + "id": 1, + "int16": int16("-32769") +}) + +insert into dataset TestDS( +{ + "id": 2, + "int16": int16("32768") +}) \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.4.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.4.ddl.aql new file mode 100644 index 0000000..40d85c01b --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.4.ddl.aql @@ -0,0 +1,47 @@ + + + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +drop dataverse test if exists; +create dataverse test; + +use dataverse test; + +create type Type as open { + id: int64, + int8: int8, + int16: int16, + int32: int32, + int64: int64 +} + +create dataset TestDS(Type) primary key id; + +insert into dataset TestDS( +{ + "id": 1, + "int32": int32("-2147483649") +}) + +insert into dataset TestDS( +{ + "id": 2, + "int32": int32("2147483648") +}) \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.5.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.5.ddl.aql new file mode 100644 index 0000000..411a78c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/types/domain_boundaries_error/domain_boundaries_error.5.ddl.aql @@ -0,0 +1,48 @@ + + + + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +drop dataverse test if exists; +create dataverse test; + +use dataverse test; + +create type Type as open { + id: int64, + int8: int8, + int16: int16, + int32: int32, + int64: int64 +} + +create dataset TestDS(Type) primary key id; + +insert into dataset TestDS( +{ + "id": 1, + "int64": int64("-9223372036854775809") +}) + +insert into dataset TestDS( +{ + "id": 2, + "int64": int64("9223372036854775808") +}) \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/domain_boundaries/domain_boundaries.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/domain_boundaries/domain_boundaries.1.adm new file mode 100644 index 0000000..81a383d --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/domain_boundaries/domain_boundaries.1.adm @@ -0,0 +1,2 @@ +{ "id": 1, "int8": -128, "int16": -32768, "int32": -2147483648, "int64": -9223372036854775808 } +{ "id": 2, "int8": 127, "int16": 32767, "int32": 2147483647, "int64": 9223372036854775807 } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml index e4af727..cbbba76 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml @@ -6946,6 +6946,20 @@ </compilation-unit> </test-case> <test-case FilePath="types"> + <compilation-unit name="domain_boundaries"> + <output-dir compare="Text">domain_boundaries</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="types"> + <compilation-unit name="domain_boundaries_error"> + <output-dir compare="Text">domain_boundaries_error</output-dir> + <expected-error>ASX0006: Invalid format for int8 in int8</expected-error> + <expected-error>ASX0006: Invalid format for int16 in int16</expected-error> + <expected-error>ASX0006: Invalid format for int32 in int32</expected-error> + <expected-error>ASX0006: Invalid format for int64 in int64</expected-error> + </compilation-unit> + </test-case> + <test-case FilePath="types"> <compilation-unit name="record01"> <output-dir compare="Text">record01</output-dir> </compilation-unit> diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java index 26fe3d8..9f3442a 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java @@ -89,16 +89,19 @@ offset = utf8Ptr.getCharStartOffset(); value = 0; positive = true; + short limit = -Short.MAX_VALUE; if (serString[offset] == '+') { offset++; } else if (serString[offset] == '-') { offset++; positive = false; + limit = Short.MIN_VALUE; } int end = startOffset + len; for (; offset < end; offset++) { if (serString[offset] >= '0' && serString[offset] <= '9') { - value = (short) (value * 10 + serString[offset] - '0'); + //accumulating value in negative domain to avoid numeric overflow + value = (short) (value * 10 - (serString[offset] - '0')); } else if (serString[offset] == 'i' && serString[offset + 1] == '1' && serString[offset + 2] == '6' && offset + 3 == end) { break; @@ -107,11 +110,11 @@ ATypeTag.SERIALIZED_INT16_TYPE_TAG); } } - if (value < 0) { + if (value > 0 || value < limit) { throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT16_TYPE_TAG); } - if (value > 0 && !positive) { + if (value < 0 && positive) { value *= -1; } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java index a186d4b..a020533 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java @@ -88,16 +88,19 @@ offset = utf8Ptr.getCharStartOffset(); value = 0; positive = true; + int limit = -Integer.MAX_VALUE; if (serString[offset] == '+') { offset++; } else if (serString[offset] == '-') { offset++; positive = false; + limit = Integer.MIN_VALUE; } int end = startOffset + len; for (; offset < end; offset++) { if (serString[offset] >= '0' && serString[offset] <= '9') { - value = value * 10 + serString[offset] - '0'; + //accumulating value in negative domain to avoid numeric overflow + value = value * 10 - (serString[offset] - '0'); } else if (serString[offset] == 'i' && serString[offset + 1] == '3' && serString[offset + 2] == '2' && offset + 3 == end) { break; @@ -106,11 +109,11 @@ ATypeTag.SERIALIZED_INT32_TYPE_TAG); } } - if (value < 0) { + if (value > 0 || value < limit) { throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT32_TYPE_TAG); } - if (value > 0 && !positive) { + if (value < 0 && positive) { value *= -1; } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java index 753b026..40e1998 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java @@ -88,16 +88,19 @@ offset = utf8Ptr.getCharStartOffset(); value = 0; positive = true; + byte limit = -Byte.MAX_VALUE; if (serString[offset] == '+') { offset++; } else if (serString[offset] == '-') { offset++; positive = false; + limit = Byte.MIN_VALUE; } int end = startOffset + len; for (; offset < end; offset++) { if (serString[offset] >= '0' && serString[offset] <= '9') { - value = (byte) (value * 10 + serString[offset] - '0'); + //accumulating value in negative domain to avoid numeric overflow + value = (byte) (value * 10 - (serString[offset] - '0')); } else if (serString[offset] == 'i' && serString[offset + 1] == '8' && offset + 2 == end) { break; @@ -106,11 +109,11 @@ ATypeTag.SERIALIZED_INT8_TYPE_TAG); } } - if (value < 0) { + if (value > 0 || value < limit) { throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG); } - if (value > 0 && !positive) { + if (value < 0 && positive) { value *= -1; } -- To view, visit https://asterix-gerrit.ics.uci.edu/1509 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0cb3411bf9a808ee87f4938c60804a8d267c36d0 Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Ildar Absalyamov <[email protected]>
