Uploaded image for project: 'Jackrabbit Oak'
  1. Jackrabbit Oak
  2. OAK-6164

IOUtils.nextPowerOf2() returns lower power of 2 for very high int values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.7.0, 1.8.0
    • commons
    • None
    • Patch

    Description

      In the IOUtils.nextPowerOf2() method, all int values are accepted as input. However, there are valid signed integer values that this method accepts as input, but for which a lower power of 2 value is returned.

      This occurs for values that are valid signed integer values that are greater than the highest possible power of two value in the signed integer range. Signed integer values have the maximum value of 0x7FFFFFFF, but the maximum possible power of two in the signed integer range is 0x40000000. (The current implementation incorrectly identifies the maximum possible power of two as 0x3FFFFFFF, due to how it is computed by doing integer division of 0x7FFFFFFF / 2.)

      In the current implementation any input in the range of [0x40000000, 0x7FFFFFFF] is a valid signed integer input, but the method will return 0x3FFFFFFF as the next valid max power of 2.

      Two minor things need to be fixed:

      • If the input is 0x40000000, the return value needs to be 0x40000000, instead of 0x3FFFFFFF which is not a valid power of 2.
      • If the input is in the range [0x40000001, 0x7FFFFFFF] I propose the method should instead throw an IllegalArgumentException and indicate that it is not possible to compute a next power of 2 for a number in that range.

      Attachments

        1. OAK-6164.patch.3
          3 kB
          Matt Ryan
        2. OAK-6164.patch.2
          4 kB
          Matt Ryan
        3. OAK-6164.patch.1
          4 kB
          Matt Ryan

        Activity

          People

            mduerig Michael Dürig
            mattvryan Matt Ryan
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: