Merge pull request #166 from cie/alexmiller/deathservice
Fix potential division by zero issues via RPC.
This commit is contained in:
commit
c3d8412abb
|
@ -267,16 +267,24 @@ struct StorageServerMetrics {
|
||||||
|
|
||||||
//static void waitMetrics( StorageServerMetrics* const& self, WaitMetricsRequest const& req );
|
//static void waitMetrics( StorageServerMetrics* const& self, WaitMetricsRequest const& req );
|
||||||
|
|
||||||
|
// This function can run on untrusted user data. We must validate all divisions carefully.
|
||||||
KeyRef getSplitKey( int64_t remaining, int64_t estimated, int64_t limits, int64_t used, int64_t infinity,
|
KeyRef getSplitKey( int64_t remaining, int64_t estimated, int64_t limits, int64_t used, int64_t infinity,
|
||||||
bool isLastShard, StorageMetricSample& sample, double divisor, KeyRef const& lastKey, KeyRef const& key ) {
|
bool isLastShard, StorageMetricSample& sample, double divisor, KeyRef const& lastKey, KeyRef const& key ) {
|
||||||
if( limits < infinity / 2 ) {
|
if( limits < infinity / 2 ) {
|
||||||
int64_t expectedSize;
|
int64_t expectedSize;
|
||||||
if( isLastShard || remaining > estimated )
|
if (limits == 0) throw Error(error_code_client_invalid_operation);
|
||||||
expectedSize = remaining / ( ( double( remaining ) / limits ) + 0.5 );
|
if( isLastShard || remaining > estimated ) {
|
||||||
else
|
double remaining_divisor = ( double( remaining ) / limits ) + 0.5;
|
||||||
expectedSize = estimated / ( ( double( estimated ) / limits ) + 0.5 );
|
if (remaining_divisor == 0) throw Error(error_code_client_invalid_operation);
|
||||||
|
expectedSize = remaining / remaining_divisor;
|
||||||
|
} else {
|
||||||
|
double estimated_divisor = ( double( estimated ) / limits ) + 0.5;
|
||||||
|
if (estimated_divisor == 0) throw Error(error_code_client_invalid_operation);
|
||||||
|
expectedSize = remaining / estimated_divisor;
|
||||||
|
}
|
||||||
|
|
||||||
if( remaining > expectedSize ) {
|
if( remaining > expectedSize ) {
|
||||||
|
if (divisor == 0) throw Error(error_code_client_invalid_operation);
|
||||||
// This does the conversion from native units to bytes using the divisor.
|
// This does the conversion from native units to bytes using the divisor.
|
||||||
double offset = (expectedSize - used) / divisor;
|
double offset = (expectedSize - used) / divisor;
|
||||||
if( offset <= 0 )
|
if( offset <= 0 )
|
||||||
|
|
Loading…
Reference in New Issue