4 Commits
Author SHA1 Message Date
andrew aeafce1bc8 Merge pull request 'SkipList: guard memcpy/memcmp against null pointers in keyAfter and friends' (#105) from weaselbot/conflict-set:weaselbot/issue-96 into main
CI / pre-commit (push) Successful in 3m7s
CI / test (arm64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 22, https://minio.weaselab.dev/public/aarch64/msan-toolchain-22.1.8.tar.zst, debug-arm64, ubuntu-latest-arm64) (push) Successful in 4m21s
CI / release (arm64, , ubuntu-latest-arm64) (push) Successful in 3m42s
CI / test (amd64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 21, https://minio.weaselab.dev/public/x86_64/msan-toolchain-21.1.8.tar.zst, debug, ubuntu-latest-amd64) (push) Successful in 5m1s
CI / test (amd64, -DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 21, , 64-bit-versions, ubuntu-latest-amd64) (push) Successful in 3m37s
CI / test (amd64, -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, 21, , gcc, ubuntu-latest-amd64) (push) Successful in 3m35s
CI / test (amd64, -DUSE_SIMD_FALLBACK=ON, 21, , simd-fallback, ubuntu-latest-amd64) (push) Successful in 3m32s
CI / release (amd64, -DMSAN_TOOLCHAIN_PATH=/opt/msan, ubuntu-latest-amd64) (push) Successful in 6m3s
CI / coverage (push) Successful in 4m11s
Reviewed-on: #105
2026-11-19 20:04:12 +00:00
andrew cce3e1651f Merge pull request 'Run the maxVersion "borrowed range version" check (#95)' (#106) from weaselbot/conflict-set:weaselbot/issue-95 into main
CI / test (arm64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 22, https://minio.weaselab.dev/public/aarch64/msan-toolchain-22.1.8.tar.zst, debug-arm64, ubuntu-latest-arm64) (push) Successful in 4m21s
CI / release (arm64, , ubuntu-latest-arm64) (push) Successful in 3m33s
CI / pre-commit (push) Successful in 2m21s
CI / test (amd64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 21, https://minio.weaselab.dev/public/x86_64/msan-toolchain-21.1.8.tar.zst, debug, ubuntu-latest-amd64) (push) Successful in 4m34s
CI / test (amd64, -DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 21, , 64-bit-versions, ubuntu-latest-amd64) (push) Successful in 3m37s
CI / test (amd64, -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, 21, , gcc, ubuntu-latest-amd64) (push) Successful in 3m35s
CI / test (amd64, -DUSE_SIMD_FALLBACK=ON, 21, , simd-fallback, ubuntu-latest-amd64) (push) Successful in 3m40s
CI / release (amd64, -DMSAN_TOOLCHAIN_PATH=/opt/msan, ubuntu-latest-amd64) (push) Successful in 6m3s
CI / coverage (push) Successful in 4m6s
Reviewed-on: #106
2026-11-18 21:22:17 +00:00
weaselbot 3d997d5c57 Run the maxVersion "borrowed range version" check
CI / test (arm64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 22, https://minio.weaselab.dev/public/aarch64/msan-toolchain-22.1.8.tar.zst, debug-arm64, ubuntu-latest-arm64) (pull_request) Successful in 4m17s
CI / release (arm64, , ubuntu-latest-arm64) (pull_request) Successful in 3m31s
CI / pre-commit (pull_request) Successful in 2m44s
CI / test (amd64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 21, https://minio.weaselab.dev/public/x86_64/msan-toolchain-21.1.8.tar.zst, debug, ubuntu-latest-amd64) (pull_request) Successful in 4m21s
CI / test (amd64, -DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 21, , 64-bit-versions, ubuntu-latest-amd64) (pull_request) Successful in 3m34s
CI / test (amd64, -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, 21, , gcc, ubuntu-latest-amd64) (pull_request) Successful in 3m30s
CI / test (amd64, -DUSE_SIMD_FALLBACK=ON, 21, , simd-fallback, ubuntu-latest-amd64) (pull_request) Successful in 3m34s
CI / release (amd64, -DMSAN_TOOLCHAIN_PATH=/opt/msan, ubuntu-latest-amd64) (pull_request) Successful in 5m58s
CI / coverage (pull_request) Successful in 3m59s
checkMaxVersion derived the key to look up from getSearchPath(root), but
`root` is the tree root, which is always the empty string. strinc("")
fails, so the block accounting for the range version of the first key
after the node's subtree never ran, for any node of any input, since it
was introduced in 9363d78. Use the node's own search path so the block
runs (and so `root` is left doing only what it was meant to do: being the
base of the search).

firstGeqLogical(), whose only caller is that block, dereferenced a null
sibling when the search key sorts after every key in the tree. It now
returns nullptr there, matching firstGeqPhysical().

Closes #95
2026-11-10 16:05:49 -05:00
weaselbot 0ca1d3c546 Guard memcpy/memcmp calls in SkipList.cpp against null pointers
CI / test (arm64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 22, https://minio.weaselab.dev/public/aarch64/msan-toolchain-22.1.8.tar.zst, debug-arm64, ubuntu-latest-arm64) (pull_request) Successful in 5m27s
CI / release (arm64, , ubuntu-latest-arm64) (pull_request) Successful in 3m31s
CI / pre-commit (pull_request) Successful in 2m13s
CI / test (amd64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 21, https://minio.weaselab.dev/public/x86_64/msan-toolchain-21.1.8.tar.zst, debug, ubuntu-latest-amd64) (pull_request) Successful in 4m1s
CI / test (amd64, -DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 21, , 64-bit-versions, ubuntu-latest-amd64) (pull_request) Successful in 3m32s
CI / test (amd64, -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, 21, , gcc, ubuntu-latest-amd64) (pull_request) Successful in 3m29s
CI / test (amd64, -DUSE_SIMD_FALLBACK=ON, 21, , simd-fallback, ubuntu-latest-amd64) (pull_request) Successful in 3m30s
CI / release (amd64, -DMSAN_TOOLCHAIN_PATH=/opt/msan, ubuntu-latest-amd64) (pull_request) Successful in 5m53s
CI / coverage (pull_request) Successful in 4m4s
keyAfter() copied the caller's key with an unguarded memcpy, so a zero-length
key spelled with a null pointer (which the header allows -- it only constrains
Key::len) became memcpy(dst, nullptr, 0). That is undefined behavior even
though the count is 0, and keyAfter() runs for every point read and point
write, so any empty-key point operation tripped UBSan builds.

Commit 2231c09 fixed this pattern in operator<(const KeyInfo&),
SkipList::less and copyToArena, but missed keyAfter(). Apply the same guard
here, and guard the remaining unguarded memcmp calls in the same file
(compare(), Finger::found() and the point-read fast path in
CheckMax::advance()) via a small equalBytes() helper.

Add test_empty_key_null_pointer, which bisimulates both implementations on an
empty key spelled with a null pointer. It fails with a UBSan trap on
SkipList.cpp:34 before this change and passes after.
2026-11-10 15:43:58 -05:00
3 changed files with 43 additions and 5 deletions

No files matched your search

+6 -1
View File
@@ -5635,6 +5635,9 @@ Node *firstGeqLogical(Node *n, const TrivialSpan key) {
goto downLeftSpine;
} else {
n = nextSibling(n);
if (n == nullptr) {
return nullptr;
}
goto downLeftSpine;
}
}
@@ -5932,7 +5935,9 @@ checkMaxVersion(Node *root, Node *node, InternalVersionT oldestVersion,
expected = std::max(expected, child->entry.rangeVersion);
}
}
auto key = getSearchPath(root);
// Account for the range version of the first key after `node`'s subtree: a
// range write spanning the subtree is recorded there.
auto key = getSearchPath(node);
bool ok;
auto inc = strinc(key, ok);
if (ok) {
+16 -4
View File
@@ -31,7 +31,9 @@
std::span<const uint8_t> keyAfter(Arena &arena, std::span<const uint8_t> key) {
auto result =
std::span<uint8_t>(new (arena) uint8_t[key.size() + 1], key.size() + 1);
memcpy(result.data(), key.data(), key.size());
if (key.size() > 0) {
memcpy(result.data(), key.data(), key.size());
}
result[result.size() - 1] = 0;
return result;
}
@@ -50,6 +52,14 @@ using Version = int64_t;
#define force_inline inline __attribute__((always_inline))
using StringRef = std::span<const uint8_t>;
// memcmp, but safe for zero-length ranges: memcmp is undefined behavior unless
// both pointers are valid, even when the count is 0, and spans for the empty
// key are allowed to have a null data().
static force_inline bool equalBytes(const uint8_t *a, const uint8_t *b,
int size) {
return size == 0 || memcmp(a, b, size) == 0;
}
struct KeyRangeRef {
StringRef begin;
StringRef end;
@@ -180,7 +190,8 @@ void sortPoints(std::vector<KeyInfo> &points) {
}
static int compare(const StringRef &a, const StringRef &b) {
int c = memcmp(a.data(), b.data(), std::min(a.size(), b.size()));
int n = std::min(a.size(), b.size());
int c = n > 0 ? memcmp(a.data(), b.data(), n) : 0;
if (c < 0)
return -1;
if (c > 0)
@@ -371,7 +382,7 @@ public:
Node *n = finger[0]->getNext(
0); // or alreadyChecked, but that is more easily invalidated
if (n && n->length() == value.size() &&
!memcmp(n->value(), value.data(), value.size()))
equalBytes(n->value(), value.data(), value.size()))
return n;
else
return nullptr;
@@ -695,7 +706,8 @@ private:
s = nextS;
if (start.finished()) {
if (nextS->length() == start.value.size() &&
!memcmp(nextS->value(), start.value.data(), start.value.size()))
equalBytes(nextS->value(), start.value.data(),
start.value.size()))
return noConflict();
else
return conflict();
+21
View File
@@ -1,4 +1,6 @@
import struct
import conflict_set
from conflict_set import *
@@ -251,6 +253,25 @@ def test_merge_child_node48():
cs.addWrites(1, write(b"\x00" * 8, b"\x00" * 10))
def test_empty_key_null_pointer():
# Regression test for issue #96: the header only constrains the length of a
# key, so a zero-length key may be spelled with a null pointer. Both
# implementations must agree on such a key, and must not pass the null
# pointer to memcpy/memcmp, which is undefined behavior even when the length
# is 0 (keyAfter() in SkipList.cpp did, on every empty-key point operation).
null_key = conflict_set._Key(None, 0)
with DebugConflictSet() as cs:
cs.addWrites(1, WriteRange(null_key, null_key))
assert cs.check(ReadRange(null_key, null_key, 0)) == [Result.CONFLICT]
assert cs.check(ReadRange(null_key, null_key, 1)) == [Result.COMMIT]
# The same operations spelled with a non-null empty key must agree.
with DebugConflictSet() as cs:
cs.addWrites(1, write(b""))
assert cs.check(read(0, b"")) == [Result.CONFLICT]
assert cs.check(read(1, b"")) == [Result.COMMIT]
def test_fixup_256_heterogeneous_versions():
# Regression test for issue #89: recomputing the maxVersion of a Node256
# must consider all of its children, not just those with an index < 16.