You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by mi...@apache.org on 2024/01/04 23:50:51 UTC

(impala) branch master updated: IMPALA-12676: Fix integer overflow in DatabaseTest

This is an automated email from the ASF dual-hosted git repository.

michaelsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


The following commit(s) were added to refs/heads/master by this push:
     new aa36259d9 IMPALA-12676: Fix integer overflow in DatabaseTest
aa36259d9 is described below

commit aa36259d9f5df180eb6ec30c8a43ca09bcc0ce4d
Author: jasonmfehr <jf...@cloudera.com>
AuthorDate: Wed Jan 3 16:23:59 2024 -0800

    IMPALA-12676: Fix integer overflow in DatabaseTest
    
    Fixes an integer overflow issue in the DatabaseTest class
    in the internal-server-test.cc file by switching from a
    signed to an unsigned int. Additional comments and
    assertions were also added to prevent future
    integer overflows.
    
    Change-Id: I3689185aa8676203226cc447585703e784627102
    Reviewed-on: http://gerrit.cloudera.org:8080/20856
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Michael Smith <mi...@cloudera.com>
---
 be/src/service/internal-server-test.cc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/be/src/service/internal-server-test.cc b/be/src/service/internal-server-test.cc
index dc0759515..e4f868864 100644
--- a/be/src/service/internal-server-test.cc
+++ b/be/src/service/internal-server-test.cc
@@ -122,6 +122,9 @@ class DatabaseTest {
   public:
     DatabaseTest(const shared_ptr<ImpalaServer> impala_server, const string name_prefix,
         const bool create_table = false, const int record_count = 5000) {
+      // See the warning on the category_count_ class member definition.
+      EXPECT_LE(category_count_, 11);
+
       this->impala_server_ = impala_server;
       this->database_name_ = StrCat(name_prefix, "_", GetCurrentTimeMicros());
       TUniqueId query_id;
@@ -146,9 +149,9 @@ class DatabaseTest {
           int cat = (i % category_count_) + 1;
           double price = cat * .01;
           // Calculate a first sold offset.
-          int first_sold = secs_per_year * (cat * cat);
+          uint32_t first_sold = secs_per_year * (cat * cat);
           // Calculate a last sold offset that is a minimum 1 year after first_sold.
-          int last_sold = first_sold - (secs_per_year * cat);
+          uint32_t last_sold = first_sold - (secs_per_year * cat);
           sql1 += StrCat("(", i, ",", cat, ",'prod_", i,
               "',seconds_sub(now(),", first_sold, "),seconds_sub(now(),", last_sold,
               "),cast(", price, " as DECIMAL(30, 2)))");
@@ -169,7 +172,7 @@ class DatabaseTest {
           int cat = (i % category_count_) + 1;
           double price = cat * .01;
           // Calculate a sold offset.
-          int sold = secs_per_year * (cat * cat);
+          uint32_t sold = secs_per_year * (cat * cat);
           sql2 += StrCat("(", i, ",", cat, ",'prod_", i,
               "',seconds_sub(now(),", sold, "),cast(", price, " as DECIMAL(30, 2)))");
 
@@ -202,6 +205,7 @@ class DatabaseTest {
     }
 
   private:
+    // WARNING: Values greater than 11 will overflow the uint32_t variables.
     const int category_count_ = 10;
     mutable string database_name_;
     mutable string table_name_;