google / google/leveldb

Invalid options range calcultion function

Open
#219 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
39.4k
Forks
8.2k
PR merge metrics
No merged PRs in 30d

Description

Original [issue 213](https://code.google.com/p/leveldb/issues/detail?id=213) created by sidorov@satissoft.ru on 2013-11-05T12:27:00.000Z:

What steps will reproduce the problem?
1. Open db providing write_buffer_size above 1G (with x64 platform)

What is the expected output? What do you see instead?

Buffer size is expected to set to the specified value, as no restrictions described in the options.h. Instead, buffer size will be set to the minimum value of 64M (not even max, as possibly writer assumed when providing SantizeOptions function implementation.

The core of the problem is that

ClipToRange

template function when called as

``` c++
ClipToRange(var_size_t, 64<<10, 1<<30);
```

will deduce template parameters as V = int,

so `static_cast(*var_size_t_ptr)` will result in possible numeric overflow when `var_size_t` is greater than `max_int`. As a result

`static_cast(*ptr) > maxvalue` will fail on common architectures and `static_cast(*ptr) < minvalue` will succeed that is opposite to the actual situation.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.