Skip to content

Commit f0e8f32

Browse files
authored
fix: another segfault in 64 bit deserialize_safe (#664)
actually update the previous_high32 variable to ensure the ghigh keys are actually strictly increasing
1 parent 032450e commit f0e8f32

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/roaring64.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,8 @@ roaring64_bitmap_t *roaring64_bitmap_portable_deserialize_safe(
19701970
roaring64_bitmap_free(r);
19711971
return NULL;
19721972
}
1973+
previous_high32 = high32;
1974+
19731975
// Read the 32-bit Roaring bitmaps representing the least significant
19741976
// bits of a set of elements.
19751977
size_t bitmap32_size = roaring_bitmap_portable_deserialize_size(

tests/roaring64_serialization.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ DEFINE_TEST(test_64deseroverlappingkeys) {
9797
// Container count - 1
9898
1, 0,
9999
// Run Flag Bitset (no runs)
100-
0, 0,
100+
0,
101101
// Upper 16 bits of the first container
102102
0, 0,
103103
// Cardinality - 1 of the first container
@@ -125,6 +125,56 @@ DEFINE_TEST(test_64deseroverlappingkeys) {
125125
roaring64_bitmap_free(r);
126126
}
127127
}
128+
129+
DEFINE_TEST(test_64deseroverlappingupper32) {
130+
// Two bitmaps, with a single array container each, at the same key (0).
131+
// clang-format off
132+
char simple_bitmap[] = {
133+
// Number of 32 bit bitmaps
134+
2, 0, 0, 0, 0, 0, 0, 0,
135+
// Top 32 bits of the first bitmap
136+
0, 0, 0, 0,
137+
// Serial Cookie
138+
0x3B, 0x30,
139+
// Container count - 1
140+
0, 0,
141+
// Run Flag Bitset (not a run)
142+
0,
143+
// Upper 16 bits of the only container
144+
0, 0,
145+
// Cardinality - 1 of the only container
146+
0, 0,
147+
// Only value of first container
148+
0, 0,
149+
// Top 32 bits of the second bitmap
150+
0, 0, 0, 0,
151+
// Serial Cookie
152+
0x3B, 0x30,
153+
// Container count - 1
154+
0, 0,
155+
// Run Flag Bitset (not a run)
156+
0,
157+
// Upper 16 bits of the only container
158+
0, 0,
159+
// Cardinality - 1 of the only container
160+
0, 0,
161+
// Only value of only container
162+
0, 0,
163+
};
164+
// clang-format on
165+
166+
roaring64_bitmap_t* r = roaring64_bitmap_portable_deserialize_safe(
167+
simple_bitmap, sizeof(simple_bitmap));
168+
const char* reason = nullptr;
169+
if (r != nullptr) {
170+
if (roaring64_bitmap_internal_validate(r, &reason)) {
171+
fail_msg(
172+
"Validation must fail if a bitmap was returned, duplicate keys "
173+
"are not allowed.");
174+
}
175+
roaring64_bitmap_free(r);
176+
}
177+
}
128178
} // namespace
129179

130180
int main() {
@@ -142,6 +192,7 @@ int main() {
142192
cmocka_unit_test(test_64mapsizetoosmall),
143193
cmocka_unit_test(test_64mapspreadvals),
144194
cmocka_unit_test(test_64deseroverlappingkeys),
195+
cmocka_unit_test(test_64deseroverlappingupper32),
145196
};
146197
return cmocka_run_group_tests(tests, NULL, NULL);
147198
#endif // CROARING_IS_BIG_ENDIAN

0 commit comments

Comments
 (0)