Fix null pointers passed to memcmp/memcpy in skip_list
CI / pre-commit (pull_request) Successful in 2m14s
CI / release (arm64, ubuntu-latest-arm64) (pull_request) Successful in 3m32s
CI / test (-DCMAKE_BUILD_TYPE=Debug, debug) (pull_request) Successful in 3m38s
CI / test (-DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 64-bit-versions) (pull_request) Successful in 3m29s
CI / test (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc) (pull_request) Successful in 3m39s
CI / test (-DUSE_SIMD_FALLBACK=ON, simd-fallback) (pull_request) Successful in 3m30s
CI / release (amd64, ubuntu-latest-amd64) (pull_request) Successful in 5m1s
CI / coverage (pull_request) Successful in 3m38s
CI / pre-commit (pull_request) Successful in 2m14s
CI / release (arm64, ubuntu-latest-arm64) (pull_request) Successful in 3m32s
CI / test (-DCMAKE_BUILD_TYPE=Debug, debug) (pull_request) Successful in 3m38s
CI / test (-DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 64-bit-versions) (pull_request) Successful in 3m29s
CI / test (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc) (pull_request) Successful in 3m39s
CI / test (-DUSE_SIMD_FALLBACK=ON, simd-fallback) (pull_request) Successful in 3m30s
CI / release (amd64, ubuntu-latest-amd64) (pull_request) Successful in 5m1s
CI / coverage (pull_request) Successful in 3m38s
In addWrites, the sizing constructor std::vector<KeyInfo>(count * 2) was used instead of reserve(count * 2), leaving count*2 default- constructed (null/empty key) entries that were then compared via operator<, passing nullptr to memcmp. Switch to reserve so only real entries exist. Additionally guard the memcmp/memcpy calls in operator<, SkipList::less, and copyToArena against empty spans (where data() may be nullptr), which is reachable on the first setOldestVersion with an empty removal key. Closes #64
This commit is contained in:
+8
-3
@@ -38,6 +38,9 @@ std::span<const uint8_t> keyAfter(Arena &arena, std::span<const uint8_t> key) {
|
|||||||
|
|
||||||
std::span<const uint8_t> copyToArena(Arena &arena,
|
std::span<const uint8_t> copyToArena(Arena &arena,
|
||||||
std::span<const uint8_t> key) {
|
std::span<const uint8_t> key) {
|
||||||
|
if (key.size() == 0) {
|
||||||
|
return std::span<const uint8_t>();
|
||||||
|
}
|
||||||
auto result = std::span<uint8_t>(new (arena) uint8_t[key.size()], key.size());
|
auto result = std::span<uint8_t>(new (arena) uint8_t[key.size()], key.size());
|
||||||
memcpy(result.data(), key.data(), key.size());
|
memcpy(result.data(), key.data(), key.size());
|
||||||
return result;
|
return result;
|
||||||
@@ -97,7 +100,7 @@ force_inline bool getCharacter(const KeyInfo &ki, int character,
|
|||||||
|
|
||||||
bool operator<(const KeyInfo &lhs, const KeyInfo &rhs) {
|
bool operator<(const KeyInfo &lhs, const KeyInfo &rhs) {
|
||||||
int i = std::min(lhs.key.size(), rhs.key.size());
|
int i = std::min(lhs.key.size(), rhs.key.size());
|
||||||
int c = memcmp(lhs.key.data(), rhs.key.data(), i);
|
int c = i > 0 ? memcmp(lhs.key.data(), rhs.key.data(), i) : 0;
|
||||||
if (c != 0)
|
if (c != 0)
|
||||||
return c < 0;
|
return c < 0;
|
||||||
|
|
||||||
@@ -287,7 +290,8 @@ private:
|
|||||||
|
|
||||||
static force_inline bool less(const uint8_t *a, int aLen, const uint8_t *b,
|
static force_inline bool less(const uint8_t *a, int aLen, const uint8_t *b,
|
||||||
int bLen) {
|
int bLen) {
|
||||||
int c = memcmp(a, b, std::min(aLen, bLen));
|
int n = std::min(aLen, bLen);
|
||||||
|
int c = n > 0 ? memcmp(a, b, n) : 0;
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return true;
|
return true;
|
||||||
if (c > 0)
|
if (c > 0)
|
||||||
@@ -754,7 +758,8 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
|||||||
|
|
||||||
void addWrites(const ConflictSet::WriteRange *writes, int count,
|
void addWrites(const ConflictSet::WriteRange *writes, int count,
|
||||||
int64_t writeVersion) {
|
int64_t writeVersion) {
|
||||||
auto points = std::vector<KeyInfo>(count * 2);
|
auto points = std::vector<KeyInfo>();
|
||||||
|
points.reserve(count * 2);
|
||||||
Arena arena;
|
Arena arena;
|
||||||
|
|
||||||
for (int r = 0; r < count; r++) {
|
for (int r = 0; r < count; r++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user