cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hao Zhong (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CASSANDRA-13675) Option can be overflowed
Date Thu, 06 Jul 2017 02:34:00 GMT
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-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message