Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3617

[C++] Integer overflow risks with Validator::count_ and Validator::counters_

    XMLWordPrintableJSON

Details

    Description

      In Validator, there seems to be some inconsistency with std::vector<size_t> counters_ and int64_t count_:

      • Validator::countingSetup converts int64_t to size_t: counters_.push_back(static_cast<size_t>(count_));
      • Validator::countingAdvance converts size_t to int: int count = --counters_.back();
      • Validator::unionAdvance converts size_t to int64_t: if (count_ < static_cast<int64_t>(node->leaves()))
      • Validator::unionAdvance converts int64_t to int and that to size_t: setupOperation(node->leafAt(static_cast<int>(count_)));

      I did not verify whether these integers can actually grow so high that overflow is possible. Nevertheless, it would be safest to use integer types consistently.

      (Originally posted as https://github.com/apache/avro/pull/1836#issuecomment-1225303643.)

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kniemitalo Kalle Niemitalo
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2.5h
                  2.5h