Skip to content

Commit

Permalink
Backport fix potential segfault in kRing due to invalid digit (#498) (#…
Browse files Browse the repository at this point in the history
…500)

* Backport fix potential segfault in kRing due to invalid digit (#498)

* Backport CI config
  • Loading branch information
isaacbrodsky authored Jul 16, 2021
1 parent ee292a9 commit 26a6409
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: test-linux

on:
push:
branches: [master]
branches: [master, stable-*]
pull_request:
branches: [master]
branches: [master, stable-*]

jobs:
tests:
Expand All @@ -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 .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: test-macos

on:
push:
branches: [master]
branches: [master, stable-*]
pull_request:
branches: [master]
branches: [master, stable-*]

jobs:
tests:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: test-website

on:
push:
branches: [master]
branches: [master, stable-*]
pull_request:
branches: [master]
branches: [master, stable-*]

jobs:
tests:
Expand All @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-node@v1
with:
node-version: 10.x
node-version: 12.x

- name: Install FOSSA
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: test-windows

on:
push:
branches: [master]
branches: [master, stable-*]
pull_request:
branches: [master]
branches: [master, stable-*]

jobs:
tests:
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.1
3.7.2
18 changes: 18 additions & 0 deletions src/apps/testapps/testKRing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 4 additions & 1 deletion src/h3lib/lib/algos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 26a6409

Please sign in to comment.