From 971a55f7e061309589f7a188b4b1ed8ebc2b2dae Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Fri, 26 Jun 2026 10:21:36 -0700 Subject: [PATCH] Cover a case in compactCells with invalid input --- src/apps/testapps/testBBoxInternal.c | 2 +- src/apps/testapps/testCompactCells.c | 13 +++++++++++++ src/h3lib/lib/h3Index.c | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/apps/testapps/testBBoxInternal.c b/src/apps/testapps/testBBoxInternal.c index 15068626cc..1c2e89048e 100644 --- a/src/apps/testapps/testBBoxInternal.c +++ b/src/apps/testapps/testBBoxInternal.c @@ -350,7 +350,7 @@ SUITE(BBox) { "bboxHexEstimate of invalid resolution fails"); } - TEST(bboxHexEstimate_invalidRes) { + TEST(bboxHexEstimate_invalidLatitudeDifference) { int64_t numHexagons; BBox bbox = {1.0, 1.0, 0.0, 1.0}; t_assert(bboxHexEstimate(&bbox, 1, &numHexagons) == E_FAILED, diff --git a/src/apps/testapps/testCompactCells.c b/src/apps/testapps/testCompactCells.c index bab73abc28..39cd5f364a 100644 --- a/src/apps/testapps/testCompactCells.c +++ b/src/apps/testapps/testCompactCells.c @@ -441,6 +441,19 @@ SUITE(compactCells) { t_assertSuccess(H3_EXPORT(compactCells)(bad, output, numHex)); } + TEST(compactCells_parentError3) { + const int numHex = 3; + H3Index bad[] = {0x81283ffffffffff, 0, 0}; + H3Index output[] = {0, 0, 0}; + + t_assertSuccess(H3_EXPORT(compactCells)(bad, output, numHex)); + t_assert(output[0] == 0x81283ffffffffff, + "output contains expected cell"); + for (int i = 1; i < numHex; i++) { + t_assert(output[i] == 0, "output contains nulls"); + } + } + TEST(uncompactCells_wrongRes) { int numHex = 3; H3Index someHexagons[] = {0, 0, 0}; diff --git a/src/h3lib/lib/h3Index.c b/src/h3lib/lib/h3Index.c index 64c11c9ef5..436a0363fd 100644 --- a/src/h3lib/lib/h3Index.c +++ b/src/h3lib/lib/h3Index.c @@ -590,7 +590,7 @@ H3Error H3_EXPORT(compactCells)(const H3Index *h3Set, H3Index *compactedSet, // to track how many times a parent is duplicated for (int64_t i = 0; i < numRemainingHexes; i++) { H3Index currIndex = remainingHexes[i]; - // TODO: This case is coverable (reachable by fuzzer) + // Can occur if 0 is passed in to the input to this function. if (currIndex != 0) { // If the reserved bits were set by the caller, the // algorithm below may encounter undefined behavior