Mirror of Darts::DoubleArray::validate(); checks root sanity, offset bounds, and leaf value bounds to catch malformed legacy files before any traversal.
| 82 | // Mirror of Darts::DoubleArray::validate(); checks root sanity, offset bounds, |
| 83 | // and leaf value bounds to catch malformed legacy files before any traversal. |
| 84 | bool ValidateLegacy64(const LegacyUnit64* arr, size_t numUnits, int maxValueLimit) { |
| 85 | if (numUnits == 0) return false; |
| 86 | if (arr[0].label() != 0 || arr[0].has_leaf() || arr[0].offset() == 0) return false; |
| 87 | if (((static_cast<size_t>(arr[0].offset())) | 0xFFu) >= numUnits) return false; |
| 88 | for (size_t i = 1; i < numUnits; ++i) { |
| 89 | uint64_t lbl = arr[i].label(); |
| 90 | if (lbl <= 0xFF) { |
| 91 | if (((i ^ static_cast<size_t>(arr[i].offset())) | 0xFFu) >= numUnits) return false; |
| 92 | } else if (maxValueLimit >= 0) { |
| 93 | if (arr[i].value() >= maxValueLimit) return false; |
| 94 | } |
| 95 | } |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | } // namespace |
| 100 |
no test coverage detected