mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 02:41:09 +00:00
c++: fix off-by-one error causing out-of-bounds access
This commit is contained in:
@@ -484,7 +484,7 @@ inline std::tuple<std::string, std::string, int> build_root_leaves(const std::fu
|
||||
std::vector<pmtiles::entryv3> root_entries;
|
||||
std::string leaves_bytes;
|
||||
int num_leaves = 0;
|
||||
for (size_t i = 0; i <= entries.size(); i += leaf_size) {
|
||||
for (size_t i = 0; i < entries.size(); i += leaf_size) {
|
||||
num_leaves++;
|
||||
int end = i + leaf_size;
|
||||
if (i + leaf_size > entries.size()) {
|
||||
|
||||
11
cpp/test.cpp
11
cpp/test.cpp
@@ -196,6 +196,16 @@ string mydecompress(const string &input, uint8_t compression) {
|
||||
return input;
|
||||
}
|
||||
|
||||
MU_TEST(test_build_dirs_one) {
|
||||
vector<entryv3> entries;
|
||||
entries.push_back(entryv3(0, 0, 1, 2));
|
||||
string root_bytes;
|
||||
string leaves_bytes;
|
||||
int num_leaves;
|
||||
tie(root_bytes, leaves_bytes, num_leaves) = build_root_leaves(&mycompress, pmtiles::COMPRESSION_NONE, entries, 1);
|
||||
mu_check(num_leaves == 1);
|
||||
}
|
||||
|
||||
MU_TEST(test_build_dirs) {
|
||||
vector<entryv3> entries;
|
||||
for (int i = 0; i < 100000; i += 2) {
|
||||
@@ -259,6 +269,7 @@ MU_TEST_SUITE(test_suite) {
|
||||
MU_RUN_TEST(test_serialize_header);
|
||||
MU_RUN_TEST(test_deserialize_header);
|
||||
MU_RUN_TEST(test_build_dirs);
|
||||
MU_RUN_TEST(test_build_dirs_one);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
Reference in New Issue
Block a user