Hao Zhong created CASSANDRA-13675:
-------------------------------------

             Summary: Option can be overflowed
                 Key: CASSANDRA-13675
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-13675
             Project: Cassandra
          Issue Type: Bug
          Components: Compaction
            Reporter: Hao Zhong
             Fix For: 4.x


The SizeTieredCompactionStrategyOptions_validateOptions method has the 
following code:
{code}
 public static Map<String, String> validateOptions(Map<String, String> options, 
Map<String, String> uncheckedOptions) throws ConfigurationException
    {
        String optionValue = options.get(MIN_SSTABLE_SIZE_KEY);
        try
        {
            long minSSTableSize = optionValue == null ? 
DEFAULT_MIN_SSTABLE_SIZE : Long.parseLong(optionValue);
            if (minSSTableSize < 0)
            {
                throw new ConfigurationException(String.format("%s must be non 
negative: %d", MIN_SSTABLE_SIZE_KEY, minSSTableSize));
            }
        }
        catch (NumberFormatException e)
        {
            throw new ConfigurationException(String.format("%s is not a 
parsable int (base10) for %s", optionValue, MIN_SSTABLE_SIZE_KEY), e);
        }
        ...
    }
{code}

Here, the optionValue can be too long and cause overflow. CASSANDRA-8406 fixed 
a similar bug. The buggy code is:
{code}
public static Map<String, String> validateOptions(Map<String, String> options, 
Map<String, String> uncheckedOptions) throws  ConfigurationException
    {
        String optionValue = options.get(TIMESTAMP_RESOLUTION_KEY);
        try
        {
            if (optionValue != null)
                TimeUnit.valueOf(optionValue);
        }
        catch (IllegalArgumentException e)
        {
            throw new 
ConfigurationException(String.format("timestamp_resolution %s is not valid", 
optionValue));
        }

        optionValue = options.get(MAX_SSTABLE_AGE_KEY);
        try
        {
            long maxSStableAge = optionValue == null ? 
DEFAULT_MAX_SSTABLE_AGE_DAYS : Long.parseLong(optionValue);
            if (maxSStableAge < 0)
            {
                throw new ConfigurationException(String.format("%s must be 
non-negative: %d", MAX_SSTABLE_AGE_KEY, maxSStableAge));
            }
        }
        catch (NumberFormatException e)
        {
            throw new ConfigurationException(String.format("%s is not a 
parsable int (base10) for %s", optionValue, MAX_SSTABLE_AGE_KEY), e);
        }
       ...
}
{code}
The fixed code uses Double to parse the input:
{code}
 public static Map<String, String> validateOptions(Map<String, String> options, 
Map<String, String> uncheckedOptions) throws  ConfigurationException
    {
        String optionValue = options.get(TIMESTAMP_RESOLUTION_KEY);
        try
        {
            if (optionValue != null)
                TimeUnit.valueOf(optionValue);
        }
        catch (IllegalArgumentException e)
        {
            throw new 
ConfigurationException(String.format("timestamp_resolution %s is not valid", 
optionValue));
        }

        optionValue = options.get(MAX_SSTABLE_AGE_KEY);
        try
        {
            double maxSStableAge = optionValue == null ? 
DEFAULT_MAX_SSTABLE_AGE_DAYS : Double.parseDouble(optionValue);
            if (maxSStableAge < 0)
            {
                throw new ConfigurationException(String.format("%s must be 
non-negative: %.2f", MAX_SSTABLE_AGE_KEY, maxSStableAge));
            }
        }
        catch (NumberFormatException e)
        {
            throw new ConfigurationException(String.format("%s is not a 
parsable int (base10) for %s", optionValue, MAX_SSTABLE_AGE_KEY), e);
        }
     ...
}
{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to