From 26a6409156ba8539b2b332f799486572f1f8bab2 Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Fri, 16 Jul 2021 16:23:34 -0700 Subject: [PATCH] Backport fix potential segfault in kRing due to invalid digit (#498) (#500) * Backport fix potential segfault in kRing due to invalid digit (#498) * Backport CI config --- .github/workflows/test-linux.yml | 6 +++--- .github/workflows/test-macos.yml | 4 ++-- .github/workflows/test-website.yml | 6 +++--- .github/workflows/test-windows.yml | 6 +++--- CHANGELOG.md | 4 ++++ VERSION | 2 +- src/apps/testapps/testKRing.c | 18 ++++++++++++++++++ src/h3lib/lib/algos.c | 5 ++++- 8 files changed, 38 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index 04244b79e..6d4a8570f 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -2,9 +2,9 @@ name: test-linux on: push: - branches: [master] + branches: [master, stable-*] pull_request: - branches: [master] + branches: [master, stable-*] jobs: tests: @@ -23,7 +23,7 @@ jobs: - name: Install Doxygen run: | sudo apt update - sudo apt-get install doxygen graphviz + sudo apt-get install doxygen graphviz clang-format-9 - name: Configure build run: cmake -Bbuild -DWARNINGS_AS_ERRORS=ON . diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index 4474fab8c..356e0141e 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -2,9 +2,9 @@ name: test-macos on: push: - branches: [master] + branches: [master, stable-*] pull_request: - branches: [master] + branches: [master, stable-*] jobs: tests: diff --git a/.github/workflows/test-website.yml b/.github/workflows/test-website.yml index 2bb16fbec..e36ee4157 100644 --- a/.github/workflows/test-website.yml +++ b/.github/workflows/test-website.yml @@ -2,9 +2,9 @@ name: test-website on: push: - branches: [master] + branches: [master, stable-*] pull_request: - branches: [master] + branches: [master, stable-*] jobs: tests: @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-node@v1 with: - node-version: 10.x + node-version: 12.x - name: Install FOSSA run: | diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index e7211cc84..0585755dc 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -2,9 +2,9 @@ name: test-windows on: push: - branches: [master] + branches: [master, stable-*] pull_request: - branches: [master] + branches: [master, stable-*] jobs: tests: @@ -24,7 +24,7 @@ jobs: - name: Configure build shell: cmd - run: cmake -Bbuild -A ${{ matrix.arch }} -DWARNINGS_AS_ERRORS=ON . + run: cmake -Bbuild -A ${{ matrix.arch }} -DWARNINGS_AS_ERRORS=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=ON . - name: Build working-directory: build diff --git a/CHANGELOG.md b/CHANGELOG.md index 909178fd4..51d2b3b11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ The public API of this library consists of the functions declared in file ## [Unreleased] +## [3.7.2] - 2021-07-15 +### Fixed +- `gridDisk` of invalid indexes should not crash. (#498) + ## [3.7.1] - 2020-10-05 ### Fixed - Finding invalid edge boundaries should not crash. (#399) diff --git a/VERSION b/VERSION index a76ccff2a..0b2eb36f5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.7.1 +3.7.2 diff --git a/src/apps/testapps/testKRing.c b/src/apps/testapps/testKRing.c index 82274b173..084c4fdd0 100644 --- a/src/apps/testapps/testKRing.c +++ b/src/apps/testapps/testKRing.c @@ -351,4 +351,22 @@ SUITE(kRing) { } } } + + TEST(kRingInvalid) { + int k = 1000; + int kSz = H3_EXPORT(maxKringSize)(k); + H3Index *neighbors = calloc(kSz, sizeof(H3Index)); + H3_EXPORT(kRing)(0x7fffffffffffffff, k, neighbors); + // Assertion is should not crash - should return an error in the future + free(neighbors); + } + + TEST(kRingInvalidDigit) { + int k = 2; + int kSz = H3_EXPORT(maxKringSize)(k); + H3Index *neighbors = calloc(kSz, sizeof(H3Index)); + H3_EXPORT(kRing)(0x4d4b00fe5c5c3030, k, neighbors); + // Assertion is should not crash - should return an error in the future + free(neighbors); + } } diff --git a/src/h3lib/lib/algos.c b/src/h3lib/lib/algos.c index d3b482194..3af83dc91 100644 --- a/src/h3lib/lib/algos.c +++ b/src/h3lib/lib/algos.c @@ -317,7 +317,10 @@ H3Index h3NeighborRotations(H3Index origin, Direction dir, int* rotations) { } else { Direction oldDigit = H3_GET_INDEX_DIGIT(out, r + 1); Direction nextDir; - if (isResClassIII(r + 1)) { + if (oldDigit == INVALID_DIGIT) { + // Only possible on invalid input + return H3_NULL; + } else if (isResClassIII(r + 1)) { H3_SET_INDEX_DIGIT(out, r + 1, NEW_DIGIT_II[oldDigit][dir]); nextDir = NEW_ADJUSTMENT_II[oldDigit][dir]; } else {